From e6c35b7b14ba815b82a7377f16b06801d68700ce Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 29 Jul 2022 17:04:24 -0500 Subject: bleh --- bash/aliases.bash | 6 + bash/functions.bash | 81 +++++++------ bootstrap.sh | 294 ++++++++++++++++++++++++------------------------ git/config | 104 ++++++++--------- profile/00_functions.sh | 5 + profile/go.sh | 4 +- profile/infopath.sh | 4 +- profile/luarocks.sh | 2 +- profile/manpath.sh | 11 +- profile/ssh-agent.sh | 10 +- user-dirs.dirs | 6 +- 11 files changed, 279 insertions(+), 248 deletions(-) diff --git a/bash/aliases.bash b/bash/aliases.bash index 7875574..7b5ed55 100644 --- a/bash/aliases.bash +++ b/bash/aliases.bash @@ -27,3 +27,9 @@ alias rebash='source ~/.bash_profile' # Debugging alias emacs_goddamnit='pushd ~/.emacs.d;emacs --debug-init;popd' + +# other +alias radio=radish +if ! command -v fd >/dev/null 2>&1; then + alias fd=fdfind +fi diff --git a/bash/functions.bash b/bash/functions.bash index 98872f2..c5bcddb 100644 --- a/bash/functions.bash +++ b/bash/functions.bash @@ -1,45 +1,62 @@ # Functions memq() { # memq ITEM ARRAY - ## Test whether an ITEM is a member of ARRAY. - ## Pass ARRAY as ${ARRAY[@]}. - local e needle="$1"; shift - for e; do - [[ "$e" == "$needle" ]] && { - return 0 - } - done - return 1 + ## Test whether an ITEM is a member of ARRAY. + ## Pass ARRAY as ${ARRAY[@]}. + local e needle="$1" + shift + for e; do + [[ "$e" == "$needle" ]] && { + return 0 + } + done + return 1 } rebashrc() { # rebashrc - ## Reload ~/.bashrc - printf "Loading ~/.bashrc..." >&2 - if source "$HOME/.bashrc"; then - echo "OK." >&2 - else - echo "ERROR!" >&2 - fi + ## Reload ~/.bashrc + printf "Loading ~/.bashrc..." >&2 + if source "$HOME/.bashrc"; then + echo "OK." >&2 + else + echo "ERROR!" >&2 + fi } first_which() { # first_which COMMAND... - ## Return the fully-qualified path of the first COMMAND found in $PATH. - while :; do - command -v "$1" && break - [ -z "$1" ] && return 1 - shift - done + ## Return the fully-qualified path of the first COMMAND found in $PATH. + while :; do + command -v "$1" && break + [ -z "$1" ] && return 1 + shift + done } 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 "$@" + # 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 "$@" } + +mkcd() { + if [ $# -lt 1 ]; then + command cd + return + fi + if ! [ -d "$1" ]; then + read -p "$1 doesn't exist. Create (Y/n)? " yn + case "$yn" in + n* | N*) return 1 ;; + *) mkdir -p "$1" ;; + esac + fi + command cd "$1" +} +alias cd='mkcd ' diff --git a/bootstrap.sh b/bootstrap.sh index 12d0b9a..b0fcb87 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -29,41 +29,41 @@ ### 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 - ;; - --) - 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 '%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 '%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. - 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" + # 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 diff --git a/git/config b/git/config index dbec691..62455ef 100644 --- a/git/config +++ b/git/config @@ -1,92 +1,94 @@ [user] - email = acdw@acdw.net - name = Case Duckworth + email = acdw@acdw.net + name = Case Duckworth [init] - defaultBranch = main + defaultBranch = main [push] - default = simple + default = simple [pull] - rebase = false + rebase = false [core] - editor = emacsclient - precomposeunicode = true - pager = less - autocrlf = false - eol = lf + editor = emacsclient + precomposeunicode = true + pager = less + autocrlf = false + eol = lf [merge] - conflictstyle = diff3 - tool = vimdiff + conflictstyle = diff3 + tool = vimdiff [alias] - # Easier locations - root = rev-parse --show-toplevel - current-branch = rev-parse --abbrev-ref HEAD - # Easier listing and info - branches = branch -a - tags = tag -l - stashes = stash list - remotes = remote -v - staged = diff --cached - graph = log --graph -10 --branches --remotes --tags --format=format:'%Cgreen%h %Creset: %<(75,trunc)%s (%cN, %cr) %Cred%d' --date-order - precommit = diff --cached --diff-algorithm=minimal -w - # Easier actions - discard = checkout -- - uncommit = reset --soft HEAD^ - unstage = reset HEAD -- - amend = commit --amend - pushall = !git remote | xargs -L1 git push --all - # Shortened commonalities - st = status -bs - ac = !git add . && git commit -m + # Easier locations + root = rev-parse --show-toplevel + current-branch = rev-parse --abbrev-ref HEAD + # Easier listing and info + branches = branch -a + tags = tag -l + stashes = stash list + remotes = remote -v + staged = diff --cached + graph = log --graph -10 --branches --remotes --tags --format=format:'%Cgreen%h %Creset: %<(75,trunc)%s (%cN, %cr) %Cred%d' --date-order + precommit = diff --cached --diff-algorithm=minimal -w + # Easier actions + discard = checkout -- + uncommit = reset --soft HEAD^ + unstage = reset HEAD -- + amend = commit --amend + pushall = !git remote | xargs -L1 git push --all + # Shortened commonalities + st = status -bs + ac = !git add . && git commit -m # diffing [diff "lisp"] - xfuncname = "^(\\(.*)$" + xfuncname = "^(\\(.*)$" [diff "org"] - xfuncname = "^(\\*+.*)$" + xfuncname = "^(\\*+.*)$" ; [credential] ; helper = /home/case/.local/bin/pass-git-helper ; useHttpPath = true [bash] - showUntrackedFiles = true - showDirtyState = true + showUntrackedFiles = true + showDirtyState = true [sendemail] - smtpserver = smtp.fastmail.com - smtpuser = acdw@fastmail.com - smtpencryption = tls - smtpserverport = 465 + smtpserver = smtp.fastmail.com + smtpuser = acdw@fastmail.com + smtpencryption = tls + smtpserverport = 465 + confirm="auto" + suppresscc = self # Better urls [url "https://github.com/"] - insteadOf = "gh:" + insteadOf = "gh:" [url "git@github.com:"] - pushInsteadOf = "gh:" + pushInsteadOf = "gh:" [github] - user = duckwork + user = duckwork [url "https://gitlab.com/"] - insteadOf = "gl:" + insteadOf = "gl:" [url "git@gitlab.com:"] - pushInsteadOf = "gl:" + pushInsteadOf = "gl:" [gitlab] - user = acdw + user = acdw [url "https://git.sr.ht/"] - insteadOf = "sr:" + insteadOf = "sr:" [url "git@git.sr.ht:"] - pushInsteadOf = "sr:" + pushInsteadOf = "sr:" [url "https://tildegit.org/"] - insteadOf = "tg:" + insteadOf = "tg:" [url "git@tildegit.org:"] - pushInsteadOf = "tg:" + pushInsteadOf = "tg:" [gitea "tildegit.org/api/v1"] - user = acdw + user = acdw diff --git a/profile/00_functions.sh b/profile/00_functions.sh index 3c67ddf..4bf0c78 100644 --- a/profile/00_functions.sh +++ b/profile/00_functions.sh @@ -62,3 +62,8 @@ path_add_unsafe() { #path_add_unsafe [-a] [-d DELIM] VAR PATH... done unset -v APPEND DELIM var } + +# Re-source ~/.profile +reprofile() { + . $HOME/.profile +} diff --git a/profile/go.sh b/profile/go.sh index 8b4ca26..205c881 100644 --- a/profile/go.sh +++ b/profile/go.sh @@ -1,9 +1,9 @@ -export GOPATH="${XDG_DATA_HOME:=$HOME/.local/share}/go" +export GOPATH="$HOME/src/go" # https://drewdevault.com/2022/05/25/Google-has-been-DDoSing-sourcehut.html export GOPROXY=direct # For the GO binary ... XXX: this is slightly clunky (~/usr/local/go/bin is the directory) -path_add_to_PATH $(realpath "$XDG_DATA_HOME/../local/go/bin") +path_add_to_PATH "$GOPATH/go/bin" command -v go >/dev/null 2>&1 && path_add_to_PATH "$(go env GOPATH)/bin" diff --git a/profile/infopath.sh b/profile/infopath.sh index 80080b8..92ecd72 100644 --- a/profile/infopath.sh +++ b/profile/infopath.sh @@ -1,7 +1,7 @@ # See 00_functions.sh for `path_add_unsafe'. path_add_unsafe INFOPATH \ - /usr/share/info \ - "${XDG_DATA_HOME:-$HOME/.local/share}/info" + /usr/share/info \ + "${XDG_DATA_HOME:-$HOME/.local/share}/info" export INFOPATH diff --git a/profile/luarocks.sh b/profile/luarocks.sh index 547a94d..e6e1d24 100644 --- a/profile/luarocks.sh +++ b/profile/luarocks.sh @@ -1,5 +1,5 @@ # add luarocks stuff to $PATH if command -v luarocks >/dev/null 2>&1; then - eval "$(luarocks path --bin)" + eval "$(luarocks path)" fi diff --git a/profile/manpath.sh b/profile/manpath.sh index 944059c..9f310e8 100644 --- a/profile/manpath.sh +++ b/profile/manpath.sh @@ -1,15 +1,16 @@ # See 00_functions.sh for `path_add_unsafe'. path_add_unsafe MANPATH \ - "${XDG_DATA_HOME:-$HOME/.local/share}/man" \ - "$HOME/.local/local/man" \ - "$HOME/usr/local/man" + "${XDG_DATA_HOME:-$HOME/.local/share}/man" \ + "$HOME/.local/local/man" \ + "$HOME/usr/local/man" \ + "$HOME/usr/man" # $MANPATH ends with `:' so that manpath(1) will prepend it to its # special thing. case "$MANPATH" in - *:) ;; - *) MANPATH="$MANPATH:" ;; +*:) ;; +*) MANPATH="$MANPATH:" ;; esac export MANPATH diff --git a/profile/ssh-agent.sh b/profile/ssh-agent.sh index 7afb7c6..95669d5 100644 --- a/profile/ssh-agent.sh +++ b/profile/ssh-agent.sh @@ -1,10 +1,10 @@ # start the ssh-agent # use keychain(1), if available -if type keychain > /dev/null 2>&1; then - # Save directory name in a variable (for ease of maintenance) - export KEYCHAIN_HOME="$XDG_RUNTIME_DIR/keychain" - eval $(keychain --eval --dir "$KEYCHAIN_HOME" --agents ssh 2>/dev/null) +if type keychain >/dev/null 2>&1; then + # Save directory name in a variable (for ease of maintenance) + export KEYCHAIN_HOME="$XDG_RUNTIME_DIR/keychain" + eval $(keychain --eval --dir "$KEYCHAIN_HOME" --agents ssh 2>/dev/null) else - eval $(ssh-agent -s) + eval $(ssh-agent -s) fi diff --git a/user-dirs.dirs b/user-dirs.dirs index 8c03e11..2b833c5 100644 --- a/user-dirs.dirs +++ b/user-dirs.dirs @@ -4,12 +4,12 @@ # Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped # homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an # absolute path. No other format is supported. -# -XDG_DESKTOP_DIR="$HOME/var/desk" +# +XDG_DESKTOP_DIR="$HOME/var/tmp" XDG_DOCUMENTS_DIR="$HOME/var/doc" XDG_DOWNLOAD_DIR="$HOME/var/download" XDG_MUSIC_DIR="$HOME/var/music" XDG_PICTURES_DIR="$HOME/var/img" XDG_PUBLICSHARE_DIR="$HOME/var/public" -XDG_TEMPLATES_DIR="$HOME/var/tmpl" +XDG_TEMPLATES_DIR="$HOME/var/templ" XDG_VIDEOS_DIR="$HOME/var/video" -- cgit 1.4.1-21-gabe81