Switch to a common shell settings between bash and zsh

This commit is contained in:
2021-03-24 18:06:42 +00:00
parent 1c49c7cecb
commit 7c210a2083
10 changed files with 58 additions and 196 deletions

View File

@@ -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)
# Source bash specific files
for f in ~/.config/bash/*.bash; do
source $f;
done

View File

@@ -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"

View File

@@ -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

View File

@@ -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
}

View File

@@ -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

View File

@@ -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

View File

@@ -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
export PS1="%F{black}[%F{white}%n@%m%F{black}] (%F{white}%1~%F{black}) %F{white}%# "

View File

@@ -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