about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xdots.sh68
1 files changed, 34 insertions, 34 deletions
diff --git a/dots.sh b/dots.sh index 5036e30..e2439f0 100755 --- a/dots.sh +++ b/dots.sh
@@ -6,25 +6,25 @@ FORCE=false
6DIR="$(dirname "$(realpath "$0")")" 6DIR="$(dirname "$(realpath "$0")")"
7 7
8main() { 8main() {
9 action=homify 9 action=homify
10 while getopts hqnfdx OPT 10 while getopts hqnfdx OPT
11 do 11 do
12 case "$OPT" in 12 case "$OPT" in
13 (h) usage; exit 0 ;; 13 (h) usage; exit 0 ;;
14 (q) QUIET=true ;; 14 (q) QUIET=true ;;
15 (n) NORUN=true ;; 15 (n) NORUN=true ;;
16 (f) FORCE=true ;; 16 (f) FORCE=true ;;
17 (d) action=dotify ;; 17 (d) action=dotify ;;
18 (x) set -x ;; 18 (x) set -x ;;
19 (*) usage; exit 1 ;; 19 (*) usage; exit 1 ;;
20 esac 20 esac
21 done 21 done
22 shift $((OPTIND - 1)) 22 shift $((OPTIND - 1))
23 "$action" "$@" 23 "$action" "$@"
24} 24}
25 25
26usage() { 26usage() {
27 cat<<EOF 27 cat<<EOF
28Usage: $0 [-h] [-q] [-n] [-f] [-x] [-d] [FILE] [FIND_ARGS...] 28Usage: $0 [-h] [-q] [-n] [-f] [-x] [-d] [FILE] [FIND_ARGS...]
29Flags: 29Flags:
30 -h Show this help and exit 30 -h Show this help and exit
@@ -49,33 +49,33 @@ log() { $QUIET || echo >&2 "* $@"; }
49run() { log "$@"; $NORUN || "$@"; } 49run() { log "$@"; $NORUN || "$@"; }
50 50
51mklink() { # mklink SOURCE DEST 51mklink() { # mklink SOURCE DEST
52 # make hardlinks to DEST from SOURCE -- making directories 52 # make hardlinks to DEST from SOURCE -- making directories
53 $NORUN || test -d "$(dirname "$2")" || run mkdir -p "$(dirname "$2")" 53 $NORUN || test -d "$(dirname "$2")" || run mkdir -p "$(dirname "$2")"
54 if ! test -f "$2" 54 if ! test -f "$2"
55 then run ln "$1" "$2" 55 then run ln "$1" "$2"
56 elif test -f "$2" && "$FORCE" 56 elif test -f "$2" && "$FORCE"
57 then run ln -f "$1" "$2" 57 then run ln -f "$1" "$2"
58 else log "$2 exists: skipping" 58 else log "$2 exists: skipping"
59 fi 59 fi
60} 60}
61 61
62getfiles() { 62getfiles() {
63 d="$1"; shift 63 d="$1"; shift
64 find "$d" -type f -a -not -name "$(basename "$0")" "$@" 64 find "$d" -type f -a -not -name "$(basename "$0")" "$@"
65} 65}
66 66
67homify() { 67homify() {
68 getfiles "$DIR" "$@" | 68 getfiles "$DIR" "$@" |
69 while read -r dot 69 while read -r dot
70 do mklink "$dot" "$HOME/.${dot#$DIR/}" 70 do mklink "$dot" "$HOME/.${dot#$DIR/}"
71 done 71 done
72} 72}
73 73
74dotify() { 74dotify() {
75 getfiles "$@" | 75 getfiles "$@" |
76 while read -r file 76 while read -r file
77 do mklink "$file" "$DIR/${file#.}" 77 do mklink "$file" "$DIR/${file#.}"
78 done 78 done
79} 79}
80 80
81main "$@" 81main "$@"