From 6fa55234f744f3e56024d36dcf0cab4df2d8d878 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 13 Mar 2022 05:30:59 +0000 Subject: Add apk --- bash/aliases.bash | 1 + 1 file changed, 1 insertion(+) diff --git a/bash/aliases.bash b/bash/aliases.bash index f2d6776..eba0673 100644 --- a/bash/aliases.bash +++ b/bash/aliases.bash @@ -8,6 +8,7 @@ sudo_cmds=( mount umount visudo + apk ) for cmd in "${sudo_cmds[@]}"; do alias $cmd="sudo $cmd" -- cgit 1.4.1-21-gabe81 From 4484a9d9d9975e78e5b2f68e0226739a4169cbe4 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 13 Mar 2022 05:31:03 +0000 Subject: Remove color from ls --- bash/aliases.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bash/aliases.bash b/bash/aliases.bash index eba0673..89c33ce 100644 --- a/bash/aliases.bash +++ b/bash/aliases.bash @@ -15,7 +15,7 @@ for cmd in "${sudo_cmds[@]}"; do done # LS -alias ls='ls -F --color=auto' +alias ls='ls -F --color=never' alias ll='ls -l' # tree alias tree='tree -F' -- cgit 1.4.1-21-gabe81 From 8b352cf25190e877a00343153fd74a3c59d93066 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 13 Mar 2022 05:31:16 +0000 Subject: Move please to functions.bash --- bash/functions.bash | 15 +++++++++++++++ bash/please.bash | 14 -------------- 2 files changed, 15 insertions(+), 14 deletions(-) delete mode 100644 bash/please.bash diff --git a/bash/functions.bash b/bash/functions.bash index 058e0f9..5e99a82 100644 --- a/bash/functions.bash +++ b/bash/functions.bash @@ -1,3 +1,5 @@ +# Functions + memq() { # memq ITEM ARRAY # Test whether an ITEM is a member of ARRAY. # Pass ARRAY as ${ARRAY[@]}. @@ -9,3 +11,16 @@ memq() { # memq ITEM ARRAY done return 1 } + +please() { # please [COMMAND...] + # if run without arguments, run the last command with 'sudo' (aka sudo !!) + # if run WITH arguments, alias as sudo + history -d -1 + if [ -z "$1" ]; then + #set -- $(HISTTIMEFORMAT=$'\t' history 2 | sed 's/^.*\t//;q') + set -- $(fc -lnr | sed 1q) + fi + echo >&2 sudo "$@" + history -s sudo "$@" + "${DEBUG:-false}" || sudo "$@" +} 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 @@ -# PLEASE -# if run without arguments, run the last command with 'sudo' (aka sudo !!) -# if run WITH arguments, alias as sudo - -please() { - history -d -1 - if [ -z "$1" ]; then - #set -- $(HISTTIMEFORMAT=$'\t' history 2 | sed 's/^.*\t//;q') - set -- $(fc -lnr | sed 1q) - fi - echo >&2 sudo "$@" - history -s sudo "$@" - "${DEBUG:-false}" || sudo "$@" -} -- cgit 1.4.1-21-gabe81 From 0d9ef0de928d21cd0104a73d1748b1c174e5b3cf Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 13 Mar 2022 05:31:38 +0000 Subject: Whitespace --- bootstrap.sh | 310 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 159 insertions(+), 151 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index d37ef6a..09b8cd6 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -29,165 +29,173 @@ ### Main entry point main() { - ## Sanity checking - # Since bootstrap.sh does some naive path-mangling, let's show an error - # if it's not run correctly. Yes, there are other ways to run a - # script. But this script should ideally be run, like, one time. Also - # you can obviously comment this out or change it if you know what - # you're doing! - - case "$0" in - ./*) ;; # this is the way bootstrap.sh /should/ be run. - *) - printf >&2 'Weird invocation! %s\n' "$*" - printf >&2 'Try: cd ; ./bootstrap.sh\n' - exit 127 - ;; - esac - - ## Variables - - # option: -d/--dry-run - : "${BOOTSTRAP_ACTION:=link}" - # option: -v/--verbose - : "${BOOTSTRAP_DEBUG:=false}" - # option: -k/--keep-going - : "${BOOTSTRAP_QUIT_ON_ERROR:=true}" - # option: -m/--manifest FILE - : "${BOOTSTRAP_MANIFEST_FILE:=bootstrap.manifest}" - # option: -- (rest are passed to ln) - : "${BOOTSTRAP_LN_ARGS:=-s}" - - ## Handle command-line flags - # Basically an easier way of setting the above variables. - while [ -n "$1" ]; do - case "$1" in - -h|--help) - cat >&2 <&2 'Weird invocation! %s\n' "$*" + printf >&2 'Try: cd ; ./bootstrap.sh\n' + exit 127 + ;; + esac + + ## Variables + + # option: -d/--dry-run + : "${BOOTSTRAP_ACTION:=link}" + # option: -v/--verbose + : "${BOOTSTRAP_DEBUG:=false}" + # option: -k/--keep-going + : "${BOOTSTRAP_QUIT_ON_ERROR:=true}" + # option: -m/--manifest FILE + : "${BOOTSTRAP_MANIFEST_FILE:=bootstrap.manifest}" + # option: -- (rest are passed to ln) + : "${BOOTSTRAP_LN_ARGS:=-s}" + + ## Handle command-line flags + # Basically an easier way of setting the above variables. + while [ -n "$1" ]; do + case "$1" in + -h|--help) + cat >&2 <&2 "Bad argument: '$2'" - exit 129 - ;; - esac - BOOTSTRAP_MANIFEST_FILE="$2" - shift 2 - ;; - -f|--force) - BOOTSTRAP_LN_ARGS="$BOOTSTRAP_LN_ARGS -f" - shift 1 - ;; - --) - BOOTSTRAP_LN_ARGS="$@" - break - ;; - esac - done - - ## Main loop - while IFS=' ' read -r source destination; do - # Ignore lines beginning with '#' - case "$source" in - '#'*) - if "$BOOTSTRAP_DEBUG"; then - printf >&2 'Skipping comment: %s %s\n' \ - "$source" "$destination" - fi - continue - ;; - esac - - # Ignore empty lines, or lines with only SOURCE or DESTINATION - if [ -z "$source" ] || [ -z "$destination" ]; then - if "$BOOTSTRAP_DEBUG"; then - printf >&2 'Skipping line: %s\t%s\n' \ - "$source" "$destination" - fi - continue - fi - - # Do the thing - if ! dispatch "$source" "$destination"; then - printf >&2 'ERROR: %s -> %s\n' \ - "$source" "$destination" - if "$BOOTSTRAP_QUIT_ON_ERROR"; then - exit "$dispatch_error" - fi - fi - done < "$BOOTSTRAP_MANIFEST_FILE" + exit + ;; + -d|--dry-run) + BOOTSTRAP_ACTION=print + shift 1 + ;; + -v|--verbose) + BOOTSTRAP_DEBUG=true + shift 1 + ;; + -k|--keep-going) + BOOTSTRAP_QUIT_ON_ERROR=false + shift 1 + ;; + -m|--manifest) + case "$2" in + ''|-*) + printf >&2 "Bad argument: '$2'" + exit 129 + ;; + esac + BOOTSTRAP_MANIFEST_FILE="$2" + shift 2 + ;; + -f|--force) + BOOTSTRAP_LN_ARGS="$BOOTSTRAP_LN_ARGS -f" + shift 1 + ;; + --) + shift 1 + BOOTSTRAP_LN_ARGS="$@" + break + ;; + esac + done + + ## Main loop + while IFS=' ' read -r source destination; do + # Ignore lines beginning with '#' + case "$source" in + '#'*) + if "$BOOTSTRAP_DEBUG"; then + printf >&2 'Skipping comment: %s %s\n' \ + "$source" "$destination" + fi + continue + ;; + esac + + # Ignore empty lines, or lines with only SOURCE or DESTINATION + if [ -z "$source" ] || [ -z "$destination" ]; then + if "$BOOTSTRAP_DEBUG"; then + printf >&2 'Skipping line: %s\t%s\n' \ + "$source" "$destination" + fi + continue + fi + + # Do the thing + if ! dispatch "$source" "$destination"; then + printf >&2 'ERROR: %s -> %s\n' \ + "$source" "$destination" + if "$BOOTSTRAP_QUIT_ON_ERROR"; then + exit "$dispatch_error" + fi + fi + done < "$BOOTSTRAP_MANIFEST_FILE" } - ### Functions dispatch() { # dispatch SOURCE DESTINATION - # Depending on environment variables, do the linking or displaying or - # whatever of a source and a destination. - - ## Variables - - src="$1" - dest="$2" - dispatch_error=0 # success - - ## Sanitize pathnames - - # If the SOURCE starts with ~, /, or $, keep it as-is; otherwise, - # prepend "$PWD/". - case "$src" in - '/'* | '~'* | '$'* ) ;; - *) src="$PWD/$src" ;; - esac - - # Convert ~ to $HOME in SOURCE and DESTINATION, to get around shell - # quoting rules. - src="$(printf '%s\n' "$src" | sed "s#^~#$HOME#")" - dest="$(printf '%s\n' "$dest" | sed "s#^~#$HOME#")" - - ## Do the thing - - # /Always/ tell the user what we're doing. - printf >&2 "ln %s %s %s\n" "$BOOTSTRAP_LN_ARGS" "$src" "$dest" - - case "$BOOTSTRAP_ACTION" in - link) # actually ... do the links - ln $BOOTSTRAP_LN_ARGS "$src" "$dest" || - dispatch_error="$?" - ;; - print) ;; # already printed. - esac - - return "$dispatch_error" + # Depending on environment variables, do the linking or displaying or + # whatever of a source and a destination. + + ## Variables + + src="$1" + dest="$2" + dispatch_error=0 # success + + ## Sanitize pathnames + + # If the SOURCE starts with ~, /, or $, keep it as-is; otherwise, + # prepend "$PWD/". + case "$src" in + '/'* | '~'* | '$'* ) ;; + *) src="$PWD/$src" ;; + esac + + # Convert ~ to $HOME in SOURCE and DESTINATION, to get around shell + # quoting rules. + src="$(printf '%s\n' "$src" | sed "s#^~#$HOME#")" + dest="$(printf '%s\n' "$dest" | sed "s#^~#$HOME#")" + + ## Do the thing + + # /Always/ tell the user what we're doing. + if [ -f "$dest" ]; then + printf >&2 'mv %s %s.old\n' "$dest" "$dest" + fi + printf >&2 "ln %s %s %s\n" "$BOOTSTRAP_LN_ARGS" "$src" "$dest" + + case "$BOOTSTRAP_ACTION" in + link) # actually ... do the links + # if DESTINATION exists, move it to DESTINATION.old + if [ -f "$dest" ]; then + mv "$dest" "$dest.old" + fi + + ln $BOOTSTRAP_LN_ARGS "$src" "$dest" || + dispatch_error="$?" + ;; + print) ;; # already printed. + esac + + return "$dispatch_error" } ### Do the thing -- cgit 1.4.1-21-gabe81 From 85312fa35b671df89887aa5c09aeb29b01d3e30a Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 13 Mar 2022 05:31:44 +0000 Subject: Silence keychain --- profile/ssh-agent.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/profile/ssh-agent.sh b/profile/ssh-agent.sh index 8e478c2..acd65a4 100644 --- a/profile/ssh-agent.sh +++ b/profile/ssh-agent.sh @@ -4,7 +4,7 @@ if type keychain > /dev/null 2>&1; then # Save directory name in a variable (for ease of maintenance) export KEYCHAIN_HOME="$HOME/.keychain" - eval $(keychain --eval --dir "$KEYCHAIN_HOME" --agents ssh) + eval $(keychain --eval --dir "$KEYCHAIN_HOME" --agents ssh 2>/dev/null) else eval $(ssh-agent -s) fi -- cgit 1.4.1-21-gabe81 From ebc1695f4cdccc1813d94177216140265e81ca2b Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 13 Mar 2022 05:32:01 +0000 Subject: Source system profile --- profile/profile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/profile/profile b/profile/profile index 7a86c76..121615f 100644 --- a/profile/profile +++ b/profile/profile @@ -1,6 +1,9 @@ # ~/.profile -*- sh -*- # vim: ft=sh +# Source system profile +source /etc/profile + # XDG directories export XDG_CONFIG_HOME="$HOME/etc" export XDG_CACHE_HOME="$HOME/var/cache" @@ -11,7 +14,7 @@ export XDG_CONFIG_DIRS="${XDG_CONFIG_DIRS:-/etc/xdg}" # source files in $XDG_CONFIG_HOME/profile if [ -d "$XDG_CONFIG_HOME/profile" ]; then - for file in "$XDG_CONFIG_HOME"/profile/*.sh; do - [ -r "$file" ] && . "$file" - done + for file in "$XDG_CONFIG_HOME"/profile/*.sh; do + [ -r "$file" ] && . "$file" + done fi -- cgit 1.4.1-21-gabe81 From 9daa93094de07cd382d59affabd91cb1681d8375 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 13 Mar 2022 05:32:13 +0000 Subject: Accomodate more types of completion setups --- bash/completion.bash | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) 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 @@ -# source completions +# Completions.bash +# Source bash completion libraries -. /etc/bash_completion +POSSIBLE_COMPLETION_FILES=( + /etc/bash_completion # Debian + /etc/profile.d/bash_completion.sh # Alpine + # I'm sure there are many more +) -# for file in /etc/bash_completion.d/*; do -# [ -r "$file" ] && source "$file" -# done +for candidate in "${POSSIBLE_COMPLETION_FILES[@]}"; do + if [[ -r "$candidate" ]]; then + source "$candidate" + break # XXX: Do I want this? + fi +done -- cgit 1.4.1-21-gabe81 From 7f435c1a60ddcdbd5459c04aace1bd021610660e Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 13 Mar 2022 05:36:45 +0000 Subject: Change prompt --- bash/prompt.bash | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/bash/prompt.bash b/bash/prompt.bash index df30c82..02d9c98 100644 --- a/bash/prompt.bash +++ b/bash/prompt.bash @@ -4,22 +4,25 @@ PS1= # user, host, and cwd PROMPT_DIRTRIM=3 # how many dirs above current to print (rest are '...') -PS1+='\[\e[36m\]\u@\h \w' +PS1+='\[\e[34m\]# \u@\h \w' # git bit # see https://unix.stackexchange.com/questions/278206 possible_git_prompt_locations=( - /usr/share/git/git-prompt.sh # Arch, etc. (default?) - /usr/lib/git-core/git-sh-prompt # Debian, Ubuntu ... - /usr/share/git-core/contrib/completion/git-prompt.sh # Fedora ?? + /usr/share/git/git-prompt.sh # Arch, etc. (default?) + /usr/lib/git-core/git-sh-prompt # Debian, Ubuntu ... + /usr/share/git-core/contrib/completion/git-prompt.sh # Fedora ?? + # I have yet to find Alpine's git prompt location. ) for file in "${possible_git_prompt_locations[@]}"; do - if [[ -f "$file" ]]; then - source "$file" && - PS1+='\[\e[35m\]$(__git_ps1)' - break - fi + if [[ -f "$file" ]]; then + source "$file" && + PS1+='\[\e[35m\]$(__git_ps1)' + break + else + true + fi done # newline @@ -27,9 +30,9 @@ PS1+='\[\e[0m\]\n' # exit code (only if error) __prompt_exit_code() { - local ec=$? - (( $ec > 0 )) && - printf "$ec" + local ec=$? + (( $ec > 0 )) && + printf "$ec" } PS1+='\[\e[31m\]$(__prompt_exit_code)\[\e[0m\]' -- cgit 1.4.1-21-gabe81 From dcb05f00e1ad6083d6a9aa0590440b5b9ef37ec1 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 13 Mar 2022 05:36:53 +0000 Subject: Whitespace and formatting --- bash/bashrc | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/bash/bashrc b/bash/bashrc index 854fe7e..e167fee 100644 --- a/bash/bashrc +++ b/bash/bashrc @@ -14,28 +14,41 @@ BASH_SOURCE_LAST=( for f in "${BASH_SOURCE_FIRST[@]}"; do file="${XDG_CONFIG_HOME:-$HOME/.config}/bash/$f.bash" - [[ -r "$file" ]] && source "$file" # || echo >&2 "no '$file' found" + if [[ -r "$file" ]]; then + # echo >&2 "Sourcing '$file'" + source "$file" + else + : + # echo >&2 "No '$file' found" + fi done for file in "$XDG_CONFIG_HOME"/bash/*.bash; do file_base="${file##*/}" - memq "${file_base%.bash}" "${BASH_SOURCE_FIRST[@]}" && { + if memq "${file_base%.bash}" "${BASH_SOURCE_FIRST[@]}"; then # echo >&2 "'$file' in BASH_SOURCE_FIRST, skipping" continue - } - memq "${file_base%.bash}" "${BASH_SOURCE_LAST[@]}" && { + elif memq "${file_base%.bash}" "${BASH_SOURCE_LAST[@]}"; then # echo >&2 "'$file' in BASH_SOURCE_LAST, skipping" continue - } - [[ -r "$file" ]] && { + elif [[ -r "$file" ]]; then # echo >&2 "Sourcing '$file'" source "$file" - } + else + : + # echo >&2 "No '$file' found" + fi unset file_base done for f in "${BASH_SOURCE_LAST[@]}"; do file="${XDG_CONFIG_HOME:-$HOME/.config}/bash/$f.bash" - [[ -r "$file" ]] && source "$file" # || echo >&2 "no '$file' found" - true + if [[ -r "$file" ]]; then + source "$file" + else + : + #echo >&2 "No '$file' found" + fi done + +true -- cgit 1.4.1-21-gabe81 From e0672f8f024b5d50101428c20dadf9e8053ee131 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 2 Apr 2022 12:38:05 -0500 Subject: Fix XDG_RUNTIME_DIR --- profile/xdg.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/profile/xdg.sh b/profile/xdg.sh index caa1a9a..7d0ed61 100644 --- a/profile/xdg.sh +++ b/profile/xdg.sh @@ -22,6 +22,4 @@ export WEECHAT_HOME="$XDG_CONFIG_HOME/weechat" export LYNX_CFG="$XDG_CONFIG_HOME/lynx/lynx.cfg" # Xorg -export XINITRC="$XDG_CONFIG_HOME/X11/xinitrc" -export XSERVERRC="$XDG_CONFIG_HOME/X11/xserverrc" -export XAUTHORITY="$XDG_RUNTIME_DIR/Xauthority" +export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-$HOME}" -- cgit 1.4.1-21-gabe81 From 00b0f259bac97003344f032d4a2df6580aa5df2d Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 2 Apr 2022 12:38:13 -0500 Subject: Set $EDITOR to emacsclient --- profile/defaults.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/profile/defaults.sh b/profile/defaults.sh index 8facc97..e167147 100644 --- a/profile/defaults.sh +++ b/profile/defaults.sh @@ -1,4 +1,5 @@ # Default programs -export EDITOR="$(which vim)" # TODO: change to emacs +export EDITOR="$(which emacsclient)" +export ALTERNATE_EDITOR= export VISUAL="$EDITOR" -- cgit 1.4.1-21-gabe81 From 8bc9628351fdb752581c421b34b4bfa07b6b4628 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 2 Apr 2022 12:38:24 -0500 Subject: Change printing --- bootstrap.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap.sh b/bootstrap.sh index 09b8cd6..12d0b9a 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -121,7 +121,7 @@ END_HELP case "$source" in '#'*) if "$BOOTSTRAP_DEBUG"; then - printf >&2 'Skipping comment: %s %s\n' \ + printf >&2 '%s %s\n' \ "$source" "$destination" fi continue -- cgit 1.4.1-21-gabe81 From c395a43660adb1917fb60b98555a97c6974c0b44 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 2 Apr 2022 12:38:31 -0500 Subject: Add xinitrc, xsession to manifest --- bootstrap.manifest | 4 ++++ 1 file changed, 4 insertions(+) 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 # Mail mail/mbsyncrc ~/.mbsyncrc +# Xorg +xorg/xinitrc ~/.xinitrc +xorg/xsession ~/.xsession + # Local Variables: # indent-tabs-mode: t # End: -- cgit 1.4.1-21-gabe81 From 03bc179ce8133d703bc9734666603a5714bfe028 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 2 Apr 2022 12:38:44 -0500 Subject: Remove dependency on tput --- bash/man.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 # on smaller terminals, use their width # (cf. https://wiki.archlinux.org/index.php/Man_page#Page_width) man() { - local width=$(tput cols) - [ $width -gt $MANWIDTH ] && width=$MANWIDTH - env MANWIDTH=$width man "$@" + local width=$COLUMNS # bashism! + [ $width -gt $MANWIDTH ] && width=$MANWIDTH + env MANWIDTH=$width man "$@" } -- cgit 1.4.1-21-gabe81 From ac5ddf2771b1e96022bd5fc98777aabaf0bd308c Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 2 Apr 2022 12:38:52 -0500 Subject: Remove apk from sudo aliases --- bash/aliases.bash | 1 - 1 file changed, 1 deletion(-) diff --git a/bash/aliases.bash b/bash/aliases.bash index 89c33ce..59e76d3 100644 --- a/bash/aliases.bash +++ b/bash/aliases.bash @@ -8,7 +8,6 @@ sudo_cmds=( mount umount visudo - apk ) for cmd in "${sudo_cmds[@]}"; do alias $cmd="sudo $cmd" -- cgit 1.4.1-21-gabe81