From 7c210a2083466b3c3ea7c24d3ecea250793d58b6 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Wed, 24 Mar 2021 18:06:42 +0000 Subject: [PATCH] Switch to a common shell settings between bash and zsh --- bash/.bashrc | 29 +++------ bash/.config/bash/aliases.bash | 12 ---- bash/.config/bash/exports.bash | 42 ------------ bash/.config/bash/functions.bash | 64 ------------------- bootstrap.sh | 2 +- .../.config/shell-common/aliases.sh | 0 shell-common/.config/shell-common/exports.sh | 40 ++++++++++++ .../.config/shell-common/functions.sh | 0 zsh/.config/zsh/exports.zsh | 40 +----------- zsh/.zshrc | 25 +++----- 10 files changed, 58 insertions(+), 196 deletions(-) delete mode 100644 bash/.config/bash/aliases.bash delete mode 100644 bash/.config/bash/functions.bash rename zsh/.config/zsh/aliases.zsh => shell-common/.config/shell-common/aliases.sh (100%) create mode 100644 shell-common/.config/shell-common/exports.sh rename zsh/.config/zsh/functions.zsh => shell-common/.config/shell-common/functions.sh (100%) diff --git a/bash/.bashrc b/bash/.bashrc index bed223c..5392d7f 100644 --- a/bash/.bashrc +++ b/bash/.bashrc @@ -5,25 +5,12 @@ if [ -f /etc/bashrc ]; then . /etc/bashrc fi -# Source exports, if it exists -if [ -f $HOME/.config/bash/exports.bash ]; then - source $HOME/.config/bash/exports.bash -fi +# Source shell common +for f in ~/.config/shell-common/*.sh; do + source $f; +done -# Source functions, if it exists -if [ -f $HOME/.config/bash/functions.bash ]; then - source $HOME/.config/bash/functions.bash -fi - -# Source aliases, if it exists -if [ -f $HOME/.config/bash/aliases.bash ]; then - source $HOME/.config/bash/aliases.bash -fi - -# Source completions, if it exists -if [ -f $HOME/.config/bash/completions.bash ]; then - source $HOME/.config/bash/completions.bash -fi - -# Homebrew -[ -d /opt/homebrew ] && eval $(/opt/homebrew/bin/brew shellenv) \ No newline at end of file +# Source bash specific files +for f in ~/.config/bash/*.bash; do + source $f; +done diff --git a/bash/.config/bash/aliases.bash b/bash/.config/bash/aliases.bash deleted file mode 100644 index df4c385..0000000 --- a/bash/.config/bash/aliases.bash +++ /dev/null @@ -1,12 +0,0 @@ -# OSX aliases -if [ $(uname) == "Darwin" ]; then - alias ls="ls -FG" - alias code="code-insiders" - alias flushdns="sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder" -else - alias ls="ls -F --color=auto" -fi - -alias t='(tmux has-session 2>/dev/null && tmux attach) || (tmux new-session)' -alias tma="tmux attach" -alias last="last | head" diff --git a/bash/.config/bash/exports.bash b/bash/.config/bash/exports.bash index 61eaa27..9c6c14e 100644 --- a/bash/.config/bash/exports.bash +++ b/bash/.config/bash/exports.bash @@ -1,44 +1,2 @@ -# User specific environment -PATH="$HOME/.local/bin:$HOME/bin:$PATH" -export PATH - # Prompt export PS1="\[\e[0;90m\][\[\e[0;37m\]\u\[\e[0;37m\]@\[\e[0;37m\]\H\[\e[0;90m\]] \[\e[0;90m\](\[\e[0;37m\]\W\[\e[0;90m\]) \[\e[0;37m\]\$\[\e[0m\] " - -# User specific environment and startup programs -export TZ=GB -export LANG=en_GB.UTF-8 - -# Make a sensible editor choice -if [ -x /usr/bin/nano ]; then - export EDITOR=nano - export VISUAL=nano -else - export EDITOR=vi - export VISUAL=vi -fi - -# Go stuff -if [ -d /usr/local/go ]; then - export GOROOT=/usr/local/go/ - export GOPATH=$HOME/go/ - export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin - - # https://github.com/oz/tz - if [ -f $HOME/go/bin/tz ]; then - export TZ_LIST="America/New_York,America/Los_Angeles,Europe/Paris" - fi -fi - -# OSX Specific envs -if [ $(uname) == "Darwin" ]; then - # Shhh Catlina, we don't care! - export BASH_SILENCE_DEPRECATION_WARNING=1 - - # M1 specific hacks - if [ $(uname -p) == "arm" ]; then - # Stop golang progs having fun with Rosetta 2 (https://yaleman.org/post/2021/2021-01-01-apple-m1-terraform-and-golang/) - export GODEBUG=asyncpreemptoff=1 - fi -fi - diff --git a/bash/.config/bash/functions.bash b/bash/.config/bash/functions.bash deleted file mode 100644 index e0fccd9..0000000 --- a/bash/.config/bash/functions.bash +++ /dev/null @@ -1,64 +0,0 @@ -# Git pulls latest dotfiles -function update-dotfiles() { - prevdir=$PWD - if [ -d "${HOME}/.dotfiles" ]; then - cd $HOME/.dotfiles - git pull --rebase --autostash - fi - if [ -d "${HOME}/.dotfiles-private" ]; then - cd $HOME/.dotfiles-private - git pull --rebase --autostash - fi - cd $prevdir -} - -function add-sshkey() { - TIMEOUT="2h" - NAME=$1 - - if [ -z "$NAME" ]; then - echo "Current Keys" - ssh-add -L | cut -d" " -f 3- - else - if [ -f "${HOME}/.ssh/id_ed25519_${NAME}" ]; then - ssh-add -t $TIMEOUT "${HOME}/.ssh/id_ed25519_${NAME}" - else - echo "No key named ${NAME} found..." - fi - fi -} - -function _add-sshkey-completions() { - COMPREPLY=( $(ls -1 ${HOME}/.ssh/id_*|cut -d'_' -f 3|cut -d'.' -f 1|sed 's/@//'|sort|uniq) ) -} -complete -F _add-sshkey-completions add-sshkey - -# Switch to a simple prompt for demos (thanks Mark H for the idea) -function demoprompt() { - if [ ! -z ${OLDPS1+x} ]; then - PS1=$OLDPS1 - unset OLDPS1 - else - OLDPS1=$PS1 - PS1=" \$ " - clear - fi -} - -function commit-pkm() { - if [ -d $HOME/Documents/pkm ]; then - prevdir=$PWD - cd ~/Documents/pkm - if [[ `git status --porcelain` ]]; then - echo "Changes detected, commiting..." - git add -A && git commit -a -m 'Manual savepoint' - else - echo "No changes detected" - fi - git fetch - if [ $(git rev-parse main) != $(git rev-parse refs/remotes/origin/main) ]; then - git push origin - fi - cd $PREVDIR - fi -} diff --git a/bootstrap.sh b/bootstrap.sh index e89b8d5..e7da8be 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -17,7 +17,7 @@ for file in .bash_profile .bashrc .bash_logout .zshrc; do done # Stow the default packages -for package in bin bash zsh; do +for package in bin shell-common bash zsh; do echo "Stowing ${package}" $HOME/.dotfiles/bin/bin/stowage install $package done diff --git a/zsh/.config/zsh/aliases.zsh b/shell-common/.config/shell-common/aliases.sh similarity index 100% rename from zsh/.config/zsh/aliases.zsh rename to shell-common/.config/shell-common/aliases.sh diff --git a/shell-common/.config/shell-common/exports.sh b/shell-common/.config/shell-common/exports.sh new file mode 100644 index 0000000..9e343e0 --- /dev/null +++ b/shell-common/.config/shell-common/exports.sh @@ -0,0 +1,40 @@ +# User specific environment +PATH="$HOME/.local/bin:$HOME/bin:$PATH" +export PATH + +# User specific environment and startup programs +export TZ=GB +export LANG=en_GB.UTF-8 + +# Make a sensible editor choice +if [ -x /usr/bin/nano ]; then + export EDITOR=nano + export VISUAL=nano +else + export EDITOR=vi + export VISUAL=vi +fi + +# Go stuff +if [ -d /usr/local/go ]; then + export GOROOT=/usr/local/go/ + export GOPATH=$HOME/go/ + export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin + + # https://github.com/oz/tz + if [ -f $HOME/go/bin/tz ]; then + export TZ_LIST="America/New_York,America/Los_Angeles,Europe/Paris" + fi +fi + +# OSX Specific envs +if [[ $(uname) == "Darwin" ]]; then + # M1 specific hacks + if [[ $(uname -p) == "arm" ]]; then + # Stop golang progs having fun with Rosetta 2 (https://yaleman.org/post/2021/2021-01-01-apple-m1-terraform-and-golang/) + export GODEBUG=asyncpreemptoff=1 + fi + + # Homebrew + [ -d /opt/homebrew ] && eval $(/opt/homebrew/bin/brew shellenv) +fi diff --git a/zsh/.config/zsh/functions.zsh b/shell-common/.config/shell-common/functions.sh similarity index 100% rename from zsh/.config/zsh/functions.zsh rename to shell-common/.config/shell-common/functions.sh diff --git a/zsh/.config/zsh/exports.zsh b/zsh/.config/zsh/exports.zsh index 5c7fbed..c828877 100644 --- a/zsh/.config/zsh/exports.zsh +++ b/zsh/.config/zsh/exports.zsh @@ -1,45 +1,7 @@ -# User specific environment -PATH="$HOME/.local/bin:$HOME/bin:$PATH" -export PATH - # History HISTFILE=${ZDOTDIR:-$HOME}/.zsh_history HISTSIZE=2000 SAVEHIST=1000 # Prompt -export PS1="%F{black}[%F{white}%n@%m%F{black}] (%F{white}%1~%F{black}) %F{white}%# " - -# User specific environment and startup programs -export TZ=GB -export LANG=en_GB.UTF-8 - -# Make a sensible editor choice -if [ -x /usr/bin/nano ]; then - export EDITOR=nano - export VISUAL=nano -else - export EDITOR=vi - export VISUAL=vi -fi - -# Go stuff -if [ -d /usr/local/go ]; then - export GOROOT=/usr/local/go/ - export GOPATH=$HOME/go/ - export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin - - # https://github.com/oz/tz - if [ -f $HOME/go/bin/tz ]; then - export TZ_LIST="America/New_York,America/Los_Angeles,Europe/Paris" - fi -fi - -# OSX Specific envs -if [[ $(uname) == "Darwin" ]]; then - # M1 specific hacks - if [[ $(uname -p) == "arm" ]]; then - # Stop golang progs having fun with Rosetta 2 (https://yaleman.org/post/2021/2021-01-01-apple-m1-terraform-and-golang/) - export GODEBUG=asyncpreemptoff=1 - fi -fi \ No newline at end of file +export PS1="%F{black}[%F{white}%n@%m%F{black}] (%F{white}%1~%F{black}) %F{white}%# " \ No newline at end of file diff --git a/zsh/.zshrc b/zsh/.zshrc index f4754a7..e055ca1 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -1,19 +1,10 @@ -# Source exports, if it exists -if [ -f $HOME/.config/zsh/exports.zsh ]; then - source $HOME/.config/zsh/exports.zsh -fi -# Source functions, if it exists -if [ -f $HOME/.config/zsh/functions.zsh ]; then - source $HOME/.config/zsh/functions.zsh -fi +# Source shell common +for f in ~/.config/shell-common/*.sh; do + source $f; +done -# Source aliases, if it exists -if [ -f $HOME/.config/zsh/aliases.zsh ]; then - source $HOME/.config/zsh/aliases.zsh -fi - -# Source completions, if it exists -if [ -f $HOME/.config/zsh/completions.zsh ]; then - source $HOME/.config/zsh/completions.zsh -fi +# Source zsh specific files +for f in ~/.config/zsh/*.zsh; do + source $f; +done