89e0f39b227438b2eebd4c4e8f0f7fc6077acc5f
David Blume Improve setup.sh portability.

David Blume authored 9 years ago

setup.sh   1) #!/usr/bin/env bash
David Blume first commit

David Blume authored 9 years ago

setup.sh   2) set -eu -o pipefail # See: https://sipb.mit.edu/doc/safe-shell/
setup.sh   3) 
dblume shell script variables lowe...

dblume authored 1 year ago

setup.sh   4) declare -r script_name=$(basename "${BASH_SOURCE[0]}")
dblume shellcheck -s bash setup.sh

dblume authored 1 year ago

setup.sh   5) declare -r backup_dir="$HOME"/backup_of_dotfiles_$(date "+%Y-%m-%d_%H%M%S")
David Blume Add .tmux.conf to list of f...

David Blume authored 4 years ago

setup.sh   6) declare -a dotfiles=(".bashrc" ".bash_profile" ".vimrc" ".editrc" ".gitconfig"
dblume Add my .gdbinit

dblume authored 2 years ago

setup.sh   7)                      ".gitignore" ".inputrc" ".tmux.conf" ".ssh/config" ".ripgreprc"
dblume Add i3 configs

dblume authored 1 year ago

setup.sh   8)                      ".gdbinit" ".config/gitui/key_bindings.ron" ".visidatarc"
dblume Add dunst config from Frame...

dblume authored 1 year ago

setup.sh   9)                      ".config/i3/config" ".config/i3status/config"
dblume Add alacritty.toml to dotfi...

dblume authored 8 months ago

setup.sh  10)                      ".config/dunst/dunstrc" ".config/alacritty/alacritty.toml")
dblume shell script variables lowe...

dblume authored 1 year ago

setup.sh  11) declare -i dry_run=0
David Blume Make setup.sh only backup c...

David Blume authored 9 years ago

setup.sh  12) 
setup.sh  13) ## exit the shell (with status 2) after printing the message
setup.sh  14) usage() {
setup.sh  15)     echo "\
dblume shell script variables lowe...

dblume authored 1 year ago

setup.sh  16) $script_name -hn
David Blume Make setup.sh only backup c...

David Blume authored 9 years ago

setup.sh  17)     -h      Print this help text
setup.sh  18)     -n      Perform a dry run, to see what'll change
setup.sh  19) "
setup.sh  20)     exit 2;
setup.sh  21) }
setup.sh  22) 
setup.sh  23) ## Process the options
setup.sh  24) while getopts "hn" OPTION
setup.sh  25) do
setup.sh  26)   case $OPTION in
setup.sh  27)     h) usage;;
dblume shell script variables lowe...

dblume authored 1 year ago

setup.sh  28)     n) dry_run=1;;
David Blume Make setup.sh only backup c...

David Blume authored 9 years ago

setup.sh  29)     \?) usage;;
setup.sh  30)   esac
setup.sh  31) done
David Blume first commit

David Blume authored 9 years ago

setup.sh  32) 
dblume shellcheck -s bash setup.sh

dblume authored 1 year ago

setup.sh  33) if [ ! -d "${backup_dir}"/.ssh ]; then
dblume shell script variables lowe...

dblume authored 1 year ago

setup.sh  34)     ((dry_run==0)) && mkdir -p "${backup_dir}"/.ssh
David Blume first commit

David Blume authored 9 years ago

setup.sh  35) fi
setup.sh  36) 
setup.sh  37) # Move original dot files to backup
David Blume Add a .gitignore file

David Blume authored 9 years ago

setup.sh  38) for i in "${dotfiles[@]}"
setup.sh  39) do
dblume shellcheck -s bash setup.sh

dblume authored 1 year ago

setup.sh  40)     if [ -e "$HOME"/"$i" ]; then
setup.sh  41)         if ! cmp --silent "$HOME"/"$i" "$i" ; then
David Blume Replaced tabs with spaces.

David Blume authored 9 years ago

setup.sh  42)             echo "$i" will be changed as follows:
dblume shellcheck -s bash setup.sh

dblume authored 1 year ago

setup.sh  43)             diff "$HOME"/"$i" "$i" || true
dblume shell script variables lowe...

dblume authored 1 year ago

setup.sh  44)             if [ $dry_run -eq 0 ]; then
dblume shellcheck -s bash setup.sh

dblume authored 1 year ago

setup.sh  45)                 mv "$HOME"/"$i" "${backup_dir}"/"$i"
David Blume Make setup.sh only backup c...

David Blume authored 9 years ago

setup.sh  46)                 # Consider using symbolic links instead
setup.sh  47)                 # so pulling updates automatically apply
dblume shellcheck -s bash setup.sh

dblume authored 1 year ago

setup.sh  48)                 cp "$i" "$HOME"/"$i"
setup.sh  49)                 echo "# vimdiff \"$HOME/$i\" \"${backup_dir}/$i\""
David Blume Make the setup script bette...

David Blume authored 6 years ago

setup.sh  50)             else
setup.sh  51)                 # Provide a diff that can still be used
setup.sh  52)                 echo "# vimdiff \"$i\" \"$HOME/$i\""
David Blume Make setup.sh only backup c...

David Blume authored 9 years ago

setup.sh  53)             fi
David Blume Make the setup script bette...

David Blume authored 6 years ago

setup.sh  54)             echo
David Blume Replaced tabs with spaces.

David Blume authored 9 years ago

setup.sh  55)         else
setup.sh  56)             echo No change to "$i".
setup.sh  57)         fi
David Blume Make setup.sh only backup c...

David Blume authored 9 years ago

setup.sh  58)     else
setup.sh  59)         echo "$i" will be added to HOME.
dblume shell script variables lowe...

dblume authored 1 year ago

setup.sh  60)         ((dry_run==0)) && mkdir -p "$HOME"/"$(dirname "$i")" && cp "$i" "$HOME"/"$i"
David Blume Add a .gitignore file

David Blume authored 9 years ago

setup.sh  61)     fi
setup.sh  62) done
David Blume first commit

David Blume authored 9 years ago

setup.sh  63) 
dblume Create an update_dir functi...

dblume authored 10 months ago

setup.sh  64) update_dir () {
setup.sh  65)     if ! diff -qr "$HOME"/"$1" "$1" > /dev/null ; then
setup.sh  66)         local parentdir="$(dirname "$1")"
setup.sh  67) 
setup.sh  68)         if [ $dry_run -eq 0 ]; then
setup.sh  69)             if [ -d "$HOME"/"$1" ]; then
setup.sh  70)                 mkdir -p "${backup_dir}"/"$parentdir"
setup.sh  71)                 mv "$HOME"/"$1" "${backup_dir}"/"$parentdir"
setup.sh  72)             else
setup.sh  73)                 mkdir -p "$HOME"/"$parentdir"
setup.sh  74)             fi
setup.sh  75)             cp -RL "$1" "$HOME"/"$parentdir"
setup.sh  76)             if [ -d "${backup_dir}"/"$1" ]; then
setup.sh  77)                 # Copy back proprietary file types (ex. ftdetect/my.vim), if any.
setup.sh  78)                 # Print only the files that got moved back into ~/"$1"
setup.sh  79)                 cp -RLnv "${backup_dir}"/"$1" "$HOME"/"$parentdir" | grep " -> " | cut -d " " -f3 | \
setup.sh  80)                     xargs -I{} sh -c "test -f {} && echo Restored {}" || true
setup.sh  81)             fi
David Blume Make the setup script bette...

David Blume authored 6 years ago

setup.sh  82)         fi
dblume Create an update_dir functi...

dblume authored 10 months ago

setup.sh  83)         if [[ -d "${backup_dir}"/"$1" ]]; then
setup.sh  84)             if ! diff -qr "$backup_dir"/"$1" "$HOME"/"$1" ; then
setup.sh  85)                 echo "# diff -qr \"$backup_dir/$1\" \"$HOME/$1\""
setup.sh  86)                 echo
setup.sh  87)             else
setup.sh  88)                 echo No change to the "$1"/ directories after restoring proprietary files.
setup.sh  89)             fi
David Blume Better output for .vim/ han...

David Blume authored 6 years ago

setup.sh  90)         else
dblume Create an update_dir functi...

dblume authored 10 months ago

setup.sh  91)             echo No "${backup_dir}"/"$1"/ from which to restore proprietary files \(yet\).
David Blume Better output for .vim/ han...

David Blume authored 6 years ago

setup.sh  92)         fi
David Blume Update some bash logic when...

David Blume authored 6 years ago

setup.sh  93)     else
dblume Create an update_dir functi...

dblume authored 10 months ago

setup.sh  94)         echo No change to the "$1"/ directories.
David Blume Add BrightScript syntax, an...

David Blume authored 8 years ago

setup.sh  95)     fi
dblume Create an update_dir functi...

dblume authored 10 months ago

setup.sh  96) }
David Blume first commit

David Blume authored 9 years ago

setup.sh  97) 
dblume Create an update_dir functi...

dblume authored 10 months ago

setup.sh  98) update_dir ".vim"
setup.sh  99) update_dir ".config/nvim"
setup.sh 100) # Neovim's plugins go in ~/.local/share/nvim/site/plugin/
dblume Add Neovim configs

dblume authored 10 months ago

setup.sh 101) # https://neovim.io/doc/user/usr_05.html
dblume Create an update_dir functi...

dblume authored 10 months ago

setup.sh 102) update_dir ".local/share/nvim/site/plugin"
dblume Add Neovim configs

dblume authored 10 months ago

setup.sh 103) 
dblume First tweaks for neovim, tw...

dblume authored 10 months ago

setup.sh 104) # Make a directory for vim undo
dblume shellcheck -s bash setup.sh

dblume authored 1 year ago

setup.sh 105) if [ ! -d "$HOME"/.vim_undo ]; then
dblume shell script variables lowe...

dblume authored 1 year ago

setup.sh 106)     ((dry_run==0)) && mkdir -p "$HOME"/.vim_undo
David Blume first commit

David Blume authored 9 years ago

setup.sh 107) fi
setup.sh 108) 
David Blume Add a reminder to copy acct...

David Blume authored 4 years ago

setup.sh 109) # I have device local secrets in .localrc and a github secret in .gitconfig.local
setup.sh 110) for i in ".gitconfig.local" ".localrc"
setup.sh 111) do
dblume shellcheck -s bash setup.sh

dblume authored 1 year ago

setup.sh 112)     if [ ! -f "$HOME"/"$i" ]; then
David Blume Add a reminder to copy acct...

David Blume authored 4 years ago

setup.sh 113)         echo Consider copying $i from a similar acct. \(\'touch \"\$HOME/$i\"\' to hide this msg.\)
setup.sh 114)     fi
setup.sh 115) done
setup.sh 116) 
dblume shell script variables lowe...

dblume authored 1 year ago

setup.sh 117) if [ $dry_run -eq 0 ]; then
dblume shellcheck -s bash setup.sh

dblume authored 1 year ago

setup.sh 118)     echo Your old dotfiles are backed up to "${backup_dir}"
David Blume Make the dry run better dis...

David Blume authored 6 years ago

setup.sh 119)     echo Done. Check http://config.dlma.com for more.
setup.sh 120) else
dblume shellcheck -s bash setup.sh

dblume authored 1 year ago

setup.sh 121)     echo Your old dotfiles would have been backed up to "${backup_dir}"