about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--bash/aliases.bash2
-rw-r--r--bash/bashrc31
-rw-r--r--bash/completion.bash18
-rw-r--r--bash/functions.bash15
-rw-r--r--bash/man.bash6
-rw-r--r--bash/please.bash14
-rw-r--r--bash/prompt.bash7
-rw-r--r--bootstrap.manifest4
-rwxr-xr-xbootstrap.sh310
-rw-r--r--profile/defaults.sh1
-rw-r--r--profile/profile3
-rw-r--r--profile/ssh-agent.sh2
-rw-r--r--profile/xdg.sh2
13 files changed, 227 insertions, 188 deletions
diff --git a/bash/aliases.bash b/bash/aliases.bash index 03361fa..7875574 100644 --- a/bash/aliases.bash +++ b/bash/aliases.bash
@@ -14,7 +14,7 @@ for cmd in "${sudo_cmds[@]}"; do
14done 14done
15 15
16# LS 16# LS
17alias ls='ls -F --color=auto' 17alias ls='ls -F --color=never'
18alias ll='ls -l' 18alias ll='ls -l'
19# tree 19# tree
20alias tree='tree -F' 20alias tree='tree -F'
diff --git a/bash/bashrc b/bash/bashrc index a1bfade..f9f17e7 100644 --- a/bash/bashrc +++ b/bash/bashrc
@@ -15,28 +15,41 @@ BASH_SOURCE_LAST=(
15 15
16for f in "${BASH_SOURCE_FIRST[@]}"; do 16for f in "${BASH_SOURCE_FIRST[@]}"; do
17 file="${XDG_CONFIG_HOME:-$HOME/.config}/bash/$f.bash" 17 file="${XDG_CONFIG_HOME:-$HOME/.config}/bash/$f.bash"
18 [[ -r "$file" ]] && source "$file" # || echo >&2 "no '$file' found" 18 if [[ -r "$file" ]]; then
19 # echo >&2 "Sourcing '$file'"
20 source "$file"
21 else
22 :
23 # echo >&2 "No '$file' found"
24 fi
19done 25done
20 26
21for file in "$XDG_CONFIG_HOME"/bash/*.bash; do 27for file in "$XDG_CONFIG_HOME"/bash/*.bash; do
22 file_base="${file##*/}" 28 file_base="${file##*/}"
23 memq "${file_base%.bash}" "${BASH_SOURCE_FIRST[@]}" && { 29 if memq "${file_base%.bash}" "${BASH_SOURCE_FIRST[@]}"; then
24 # echo >&2 "'$file' in BASH_SOURCE_FIRST, skipping" 30 # echo >&2 "'$file' in BASH_SOURCE_FIRST, skipping"
25 continue 31 continue
26 } 32 elif memq "${file_base%.bash}" "${BASH_SOURCE_LAST[@]}"; then
27 memq "${file_base%.bash}" "${BASH_SOURCE_LAST[@]}" && {
28 # echo >&2 "'$file' in BASH_SOURCE_LAST, skipping" 33 # echo >&2 "'$file' in BASH_SOURCE_LAST, skipping"
29 continue 34 continue
30 } 35 elif [[ -r "$file" ]]; then
31 [[ -r "$file" ]] && {
32 # echo >&2 "Sourcing '$file'" 36 # echo >&2 "Sourcing '$file'"
33 source "$file" 37 source "$file"
34 } 38 else
39 :
40 # echo >&2 "No '$file' found"
41 fi
35 unset file_base 42 unset file_base
36done 43done
37 44
38for f in "${BASH_SOURCE_LAST[@]}"; do 45for f in "${BASH_SOURCE_LAST[@]}"; do
39 file="${XDG_CONFIG_HOME:-$HOME/.config}/bash/$f.bash" 46 file="${XDG_CONFIG_HOME:-$HOME/.config}/bash/$f.bash"
40 [[ -r "$file" ]] && source "$file" # || echo >&2 "no '$file' found" 47 if [[ -r "$file" ]]; then
41 true 48 source "$file"
49 else
50 :
51 #echo >&2 "No '$file' found"
52 fi
42done 53done
54
55true
diff --git a/bash/completion.bash b/bash/completion.bash index 50e8f35..764463e 100644 --- a/bash/completion.bash +++ b/bash/completion.bash
@@ -1,7 +1,15 @@
1# source completions 1# Completions.bash
2# Source bash completion libraries
2 3
3. /etc/bash_completion 4POSSIBLE_COMPLETION_FILES=(
5 /etc/bash_completion # Debian
6 /etc/profile.d/bash_completion.sh # Alpine
7 # I'm sure there are many more
8)
4 9
5# for file in /etc/bash_completion.d/*; do 10for candidate in "${POSSIBLE_COMPLETION_FILES[@]}"; do
6# [ -r "$file" ] && source "$file" 11 if [[ -r "$candidate" ]]; then
7# done 12 source "$candidate"
13 break # XXX: Do I want this?
14 fi
15done
diff --git a/bash/functions.bash b/bash/functions.bash index cce92be..98872f2 100644 --- a/bash/functions.bash +++ b/bash/functions.bash
@@ -1,3 +1,5 @@
1# Functions
2
1memq() { # memq ITEM ARRAY 3memq() { # memq ITEM ARRAY
2 ## Test whether an ITEM is a member of ARRAY. 4 ## Test whether an ITEM is a member of ARRAY.
3 ## Pass ARRAY as ${ARRAY[@]}. 5 ## Pass ARRAY as ${ARRAY[@]}.
@@ -28,3 +30,16 @@ first_which() { # first_which COMMAND...
28 shift 30 shift
29 done 31 done
30} 32}
33
34please() { # please [COMMAND...]
35 # if run without arguments, run the last command with 'sudo' (aka sudo !!)
36 # if run WITH arguments, alias as sudo
37 history -d -1
38 if [ -z "$1" ]; then
39 #set -- $(HISTTIMEFORMAT=$'\t' history 2 | sed 's/^.*\t//;q')
40 set -- $(fc -lnr | sed 1q)
41 fi
42 echo >&2 sudo "$@"
43 history -s sudo "$@"
44 "${DEBUG:-false}" || sudo "$@"
45}
diff --git a/bash/man.bash b/bash/man.bash index 4927952..5a28066 100644 --- a/bash/man.bash +++ b/bash/man.bash
@@ -3,7 +3,7 @@ export MANWIDTH=80
3# on smaller terminals, use their width 3# on smaller terminals, use their width
4# (cf. https://wiki.archlinux.org/index.php/Man_page#Page_width) 4# (cf. https://wiki.archlinux.org/index.php/Man_page#Page_width)
5man() { 5man() {
6 local width=$(tput cols) 6 local width=$COLUMNS # bashism!
7 [ $width -gt $MANWIDTH ] && width=$MANWIDTH 7 [ $width -gt $MANWIDTH ] && width=$MANWIDTH
8 env MANWIDTH=$width man "$@" 8 env MANWIDTH=$width man "$@"
9} 9}
diff --git a/bash/please.bash b/bash/please.bash deleted file mode 100644 index 179ed17..0000000 --- a/bash/please.bash +++ /dev/null
@@ -1,14 +0,0 @@
1# PLEASE
2# if run without arguments, run the last command with 'sudo' (aka sudo !!)
3# if run WITH arguments, alias as sudo
4
5please() {
6 history -d -1
7 if [ -z "$1" ]; then
8 #set -- $(HISTTIMEFORMAT=$'\t' history 2 | sed 's/^.*\t//;q')
9 set -- $(fc -lnr | sed 1q)
10 fi
11 echo >&2 sudo "$@"
12 history -s sudo "$@"
13 "${DEBUG:-false}" || sudo "$@"
14}
diff --git a/bash/prompt.bash b/bash/prompt.bash index dfb84ca..f1bdd69 100644 --- a/bash/prompt.bash +++ b/bash/prompt.bash
@@ -9,9 +9,10 @@ PS1+='\[\e[0;46m\]\u@\h \w'
9# git bit 9# git bit
10# see https://unix.stackexchange.com/questions/278206 10# see https://unix.stackexchange.com/questions/278206
11possible_git_prompt_locations=( 11possible_git_prompt_locations=(
12 /usr/share/git/git-prompt.sh # Arch, etc. (default?) 12 /usr/share/git/git-prompt.sh # Arch, etc. (default?)
13 /usr/lib/git-core/git-sh-prompt # Debian, Ubuntu ... 13 /usr/lib/git-core/git-sh-prompt # Debian, Ubuntu ...
14 /usr/share/git-core/contrib/completion/git-prompt.sh # Fedora ?? 14 /usr/share/git-core/contrib/completion/git-prompt.sh # Fedora ??
15 # I have yet to find Alpine's git prompt location.
15) 16)
16 17
17for file in "${possible_git_prompt_locations[@]}"; do 18for file in "${possible_git_prompt_locations[@]}"; do
diff --git a/bootstrap.manifest b/bootstrap.manifest index 825ee92..ad315db 100644 --- a/bootstrap.manifest +++ b/bootstrap.manifest
@@ -17,6 +17,10 @@ profile/profile ~/.profile
17# Mail 17# Mail
18mail/mbsyncrc ~/.mbsyncrc 18mail/mbsyncrc ~/.mbsyncrc
19 19
20# Xorg
21xorg/xinitrc ~/.xinitrc
22xorg/xsession ~/.xsession
23
20# Local Variables: 24# Local Variables:
21# indent-tabs-mode: t 25# indent-tabs-mode: t
22# End: 26# End:
diff --git a/bootstrap.sh b/bootstrap.sh index d37ef6a..12d0b9a 100755 --- a/bootstrap.sh +++ b/bootstrap.sh
@@ -29,165 +29,173 @@
29### Main entry point 29### Main entry point
30 30
31main() { 31main() {
32 ## Sanity checking 32 ## Sanity checking
33 # Since bootstrap.sh does some naive path-mangling, let's show an error 33 # Since bootstrap.sh does some naive path-mangling, let's show an error
34 # if it's not run correctly. Yes, there are other ways to run a 34 # if it's not run correctly. Yes, there are other ways to run a
35 # script. But this script should ideally be run, like, one time. Also 35 # script. But this script should ideally be run, like, one time. Also
36 # you can obviously comment this out or change it if you know what 36 # you can obviously comment this out or change it if you know what
37 # you're doing! 37 # you're doing!
38 38
39 case "$0" in 39 case "$0" in
40 ./*) ;; # this is the way bootstrap.sh /should/ be run. 40 ./*) ;; # this is the way bootstrap.sh /should/ be run.
41 *) 41 *)
42 printf >&2 'Weird invocation! %s\n' "$*" 42 printf >&2 'Weird invocation! %s\n' "$*"
43 printf >&2 'Try: cd <bootstrap-dir>; ./bootstrap.sh\n' 43 printf >&2 'Try: cd <bootstrap-dir>; ./bootstrap.sh\n'
44 exit 127 44 exit 127
45 ;; 45 ;;
46 esac 46 esac
47 47
48 ## Variables 48 ## Variables
49 49
50 # option: -d/--dry-run 50 # option: -d/--dry-run
51 : "${BOOTSTRAP_ACTION:=link}" 51 : "${BOOTSTRAP_ACTION:=link}"
52 # option: -v/--verbose 52 # option: -v/--verbose
53 : "${BOOTSTRAP_DEBUG:=false}" 53 : "${BOOTSTRAP_DEBUG:=false}"
54 # option: -k/--keep-going 54 # option: -k/--keep-going
55 : "${BOOTSTRAP_QUIT_ON_ERROR:=true}" 55 : "${BOOTSTRAP_QUIT_ON_ERROR:=true}"
56 # option: -m/--manifest FILE 56 # option: -m/--manifest FILE
57 : "${BOOTSTRAP_MANIFEST_FILE:=bootstrap.manifest}" 57 : "${BOOTSTRAP_MANIFEST_FILE:=bootstrap.manifest}"
58 # option: -- (rest are passed to ln) 58 # option: -- (rest are passed to ln)
59 : "${BOOTSTRAP_LN_ARGS:=-s}" 59 : "${BOOTSTRAP_LN_ARGS:=-s}"
60 60
61 ## Handle command-line flags 61 ## Handle command-line flags
62 # Basically an easier way of setting the above variables. 62 # Basically an easier way of setting the above variables.
63 while [ -n "$1" ]; do 63 while [ -n "$1" ]; do
64 case "$1" in 64 case "$1" in
65 -h|--help) 65 -h|--help)
66 cat >&2 <<END_HELP 66 cat >&2 <<END_HELP
67Usage: ./bootstrap.sh [-d] [-v] [-k] [-m FILE] [-f] [-- LN_OPTS] 67Usage: ./bootstrap.sh [-d] [-v] [-k] [-m FILE] [-f] [-- LN_OPTS]
68OPTIONS: 68OPTIONS:
69 -d, --dry-run 69 -d, --dry-run
70 Only print what would happen. 70 Only print what would happen.
71 -v, --verbose 71 -v, --verbose
72 Be more verbose about things. 72 Be more verbose about things.
73 -k, --keep-going 73 -k, --keep-going
74 Keep going after an error. 74 Keep going after an error.
75 -f, --force 75 -f, --force
76 Force linking. Passes -f to ln. 76 Force linking. Passes -f to ln.
77 -m FILE, --manifest FILE 77 -m FILE, --manifest FILE
78 Use FILE as manifest. 78 Use FILE as manifest.
79 Default: bootstrap.manifest. 79 Default: bootstrap.manifest.
80 -- Signify end of options. The rest are passed to ln. 80 -- Signify end of options. The rest are passed to ln.
81END_HELP 81END_HELP
82 exit 82 exit
83 ;; 83 ;;
84 -d|--dry-run) 84 -d|--dry-run)
85 BOOTSTRAP_ACTION=print 85 BOOTSTRAP_ACTION=print
86 shift 1 86 shift 1
87 ;; 87 ;;
88 -v|--verbose) 88 -v|--verbose)
89 BOOTSTRAP_DEBUG=true 89 BOOTSTRAP_DEBUG=true
90 shift 1 90 shift 1
91 ;; 91 ;;
92 -k|--keep-going) 92 -k|--keep-going)
93 BOOTSTRAP_QUIT_ON_ERROR=false 93 BOOTSTRAP_QUIT_ON_ERROR=false
94 shift 1 94 shift 1
95 ;; 95 ;;
96 -m|--manifest) 96 -m|--manifest)
97 case "$2" in 97 case "$2" in
98 ''|-*) 98 ''|-*)
99 printf >&2 "Bad argument: '$2'" 99 printf >&2 "Bad argument: '$2'"
100 exit 129 100 exit 129
101 ;; 101 ;;
102 esac 102 esac
103 BOOTSTRAP_MANIFEST_FILE="$2" 103 BOOTSTRAP_MANIFEST_FILE="$2"
104 shift 2 104 shift 2
105 ;; 105 ;;
106 -f|--force) 106 -f|--force)
107 BOOTSTRAP_LN_ARGS="$BOOTSTRAP_LN_ARGS -f" 107 BOOTSTRAP_LN_ARGS="$BOOTSTRAP_LN_ARGS -f"
108 shift 1 108 shift 1
109 ;; 109 ;;
110 --) 110 --)
111 BOOTSTRAP_LN_ARGS="$@" 111 shift 1
112 break 112 BOOTSTRAP_LN_ARGS="$@"
113 ;; 113 break
114 esac 114 ;;
115 done 115 esac
116 116 done
117 ## Main loop 117
118 while IFS=' ' read -r source destination; do 118 ## Main loop
119 # Ignore lines beginning with '#' 119 while IFS=' ' read -r source destination; do
120 case "$source" in 120 # Ignore lines beginning with '#'
121 '#'*) 121 case "$source" in
122 if "$BOOTSTRAP_DEBUG"; then 122 '#'*)
123 printf >&2 'Skipping comment: %s %s\n' \ 123 if "$BOOTSTRAP_DEBUG"; then
124 "$source" "$destination" 124 printf >&2 '%s %s\n' \
125 fi 125 "$source" "$destination"
126 continue 126 fi
127 ;; 127 continue
128 esac 128 ;;
129 129 esac
130 # Ignore empty lines, or lines with only SOURCE or DESTINATION 130
131 if [ -z "$source" ] || [ -z "$destination" ]; then 131 # Ignore empty lines, or lines with only SOURCE or DESTINATION
132 if "$BOOTSTRAP_DEBUG"; then 132 if [ -z "$source" ] || [ -z "$destination" ]; then
133 printf >&2 'Skipping line: %s\t%s\n' \ 133 if "$BOOTSTRAP_DEBUG"; then
134 "$source" "$destination" 134 printf >&2 'Skipping line: %s\t%s\n' \
135 fi 135 "$source" "$destination"
136 continue 136 fi
137 fi 137 continue
138 138 fi
139 # Do the thing 139
140 if ! dispatch "$source" "$destination"; then 140 # Do the thing
141 printf >&2 'ERROR: %s -> %s\n' \ 141 if ! dispatch "$source" "$destination"; then
142 "$source" "$destination" 142 printf >&2 'ERROR: %s -> %s\n' \
143 if "$BOOTSTRAP_QUIT_ON_ERROR"; then 143 "$source" "$destination"
144 exit "$dispatch_error" 144 if "$BOOTSTRAP_QUIT_ON_ERROR"; then
145 fi 145 exit "$dispatch_error"
146 fi 146 fi
147 done < "$BOOTSTRAP_MANIFEST_FILE" 147 fi
148 done < "$BOOTSTRAP_MANIFEST_FILE"
148} 149}
149 150
150
151### Functions 151### Functions
152 152
153dispatch() { # dispatch SOURCE DESTINATION 153dispatch() { # dispatch SOURCE DESTINATION
154 # Depending on environment variables, do the linking or displaying or 154 # Depending on environment variables, do the linking or displaying or
155 # whatever of a source and a destination. 155 # whatever of a source and a destination.
156 156
157 ## Variables 157 ## Variables
158 158
159 src="$1" 159 src="$1"
160 dest="$2" 160 dest="$2"
161 dispatch_error=0 # success 161 dispatch_error=0 # success
162 162
163 ## Sanitize pathnames 163 ## Sanitize pathnames
164 164
165 # If the SOURCE starts with ~, /, or $, keep it as-is; otherwise, 165 # If the SOURCE starts with ~, /, or $, keep it as-is; otherwise,
166 # prepend "$PWD/". 166 # prepend "$PWD/".
167 case "$src" in 167 case "$src" in
168 '/'* | '~'* | '$'* ) ;; 168 '/'* | '~'* | '$'* ) ;;
169 *) src="$PWD/$src" ;; 169 *) src="$PWD/$src" ;;
170 esac 170 esac
171 171
172 # Convert ~ to $HOME in SOURCE and DESTINATION, to get around shell 172 # Convert ~ to $HOME in SOURCE and DESTINATION, to get around shell
173 # quoting rules. 173 # quoting rules.
174 src="$(printf '%s\n' "$src" | sed "s#^~#$HOME#")" 174 src="$(printf '%s\n' "$src" | sed "s#^~#$HOME#")"
175 dest="$(printf '%s\n' "$dest" | sed "s#^~#$HOME#")" 175 dest="$(printf '%s\n' "$dest" | sed "s#^~#$HOME#")"
176 176
177 ## Do the thing 177 ## Do the thing
178 178
179 # /Always/ tell the user what we're doing. 179 # /Always/ tell the user what we're doing.
180 printf >&2 "ln %s %s %s\n" "$BOOTSTRAP_LN_ARGS" "$src" "$dest" 180 if [ -f "$dest" ]; then
181 181 printf >&2 'mv %s %s.old\n' "$dest" "$dest"
182 case "$BOOTSTRAP_ACTION" in 182 fi
183 link) # actually ... do the links 183 printf >&2 "ln %s %s %s\n" "$BOOTSTRAP_LN_ARGS" "$src" "$dest"
184 ln $BOOTSTRAP_LN_ARGS "$src" "$dest" || 184
185 dispatch_error="$?" 185 case "$BOOTSTRAP_ACTION" in
186 ;; 186 link) # actually ... do the links
187 print) ;; # already printed. 187 # if DESTINATION exists, move it to DESTINATION.old
188 esac 188 if [ -f "$dest" ]; then
189 189 mv "$dest" "$dest.old"
190 return "$dispatch_error" 190 fi
191
192 ln $BOOTSTRAP_LN_ARGS "$src" "$dest" ||
193 dispatch_error="$?"
194 ;;
195 print) ;; # already printed.
196 esac
197
198 return "$dispatch_error"
191} 199}
192 200
193### Do the thing 201### Do the thing
diff --git a/profile/defaults.sh b/profile/defaults.sh index 347e0e5..e167147 100644 --- a/profile/defaults.sh +++ b/profile/defaults.sh
@@ -1,4 +1,5 @@
1# Default programs 1# Default programs
2 2
3export EDITOR="$(which emacsclient)" 3export EDITOR="$(which emacsclient)"
4export ALTERNATE_EDITOR=
4export VISUAL="$EDITOR" 5export VISUAL="$EDITOR"
diff --git a/profile/profile b/profile/profile index a0dc281..a531e8e 100644 --- a/profile/profile +++ b/profile/profile
@@ -1,6 +1,9 @@
1# ~/.profile -*- sh -*- 1# ~/.profile -*- sh -*-
2# vim: ft=sh 2# vim: ft=sh
3 3
4# Source system profile
5source /etc/profile
6
4# XDG directories 7# XDG directories
5export XDG_CONFIG_HOME="$HOME/etc" 8export XDG_CONFIG_HOME="$HOME/etc"
6export XDG_CACHE_HOME="$HOME/var/cache" 9export XDG_CACHE_HOME="$HOME/var/cache"
diff --git a/profile/ssh-agent.sh b/profile/ssh-agent.sh index 7af5219..acd65a4 100644 --- a/profile/ssh-agent.sh +++ b/profile/ssh-agent.sh
@@ -4,7 +4,7 @@
4if type keychain > /dev/null 2>&1; then 4if type keychain > /dev/null 2>&1; then
5 # Save directory name in a variable (for ease of maintenance) 5 # Save directory name in a variable (for ease of maintenance)
6 export KEYCHAIN_HOME="$HOME/.keychain" 6 export KEYCHAIN_HOME="$HOME/.keychain"
7 eval $(keychain --eval --dir "$KEYCHAIN_HOME" --agents ssh -q) 7 eval $(keychain --eval --dir "$KEYCHAIN_HOME" --agents ssh 2>/dev/null)
8else 8else
9 eval $(ssh-agent -s) 9 eval $(ssh-agent -s)
10fi 10fi
diff --git a/profile/xdg.sh b/profile/xdg.sh index ed58c4f..71ab6bb 100644 --- a/profile/xdg.sh +++ b/profile/xdg.sh
@@ -22,9 +22,9 @@ export WEECHAT_HOME="$XDG_CONFIG_HOME/weechat"
22export LYNX_CFG="$XDG_CONFIG_HOME/lynx/lynx.cfg" 22export LYNX_CFG="$XDG_CONFIG_HOME/lynx/lynx.cfg"
23 23
24# Xorg 24# Xorg
25export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-$HOME}"
25export XINITRC="$XDG_CONFIG_HOME/X11/xinitrc" 26export XINITRC="$XDG_CONFIG_HOME/X11/xinitrc"
26export XSERVERRC="$XDG_CONFIG_HOME/X11/xserverrc" 27export XSERVERRC="$XDG_CONFIG_HOME/X11/xserverrc"
27export XAUTHORITY="$XDG_RUNTIME_DIR/Xauthority"
28 28
29# Notmuch 29# Notmuch
30export NOTMUCH_CONFIG="${XDG_CONFIG_HOME:=$HOME/.config}/notmuch/config" 30export NOTMUCH_CONFIG="${XDG_CONFIG_HOME:=$HOME/.config}/notmuch/config"