From 03bc920b74fc4d5246b3723fef4ffa12a266944e Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Wed, 24 Mar 2021 17:46:57 +0000 Subject: [PATCH] Add zsh config --- zsh/.config/zsh/aliases.zsh | 12 +++++++ zsh/.config/zsh/exports.zsh | 45 ++++++++++++++++++++++++++ zsh/.config/zsh/functions.zsh | 59 +++++++++++++++++++++++++++++++++++ zsh/.zshrc | 19 +++++++++++ 4 files changed, 135 insertions(+) create mode 100644 zsh/.config/zsh/aliases.zsh create mode 100644 zsh/.config/zsh/exports.zsh create mode 100644 zsh/.config/zsh/functions.zsh create mode 100644 zsh/.zshrc diff --git a/zsh/.config/zsh/aliases.zsh b/zsh/.config/zsh/aliases.zsh new file mode 100644 index 0000000..b3acaa9 --- /dev/null +++ b/zsh/.config/zsh/aliases.zsh @@ -0,0 +1,12 @@ +# 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" \ No newline at end of file diff --git a/zsh/.config/zsh/exports.zsh b/zsh/.config/zsh/exports.zsh new file mode 100644 index 0000000..5c7fbed --- /dev/null +++ b/zsh/.config/zsh/exports.zsh @@ -0,0 +1,45 @@ +# 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 diff --git a/zsh/.config/zsh/functions.zsh b/zsh/.config/zsh/functions.zsh new file mode 100644 index 0000000..da57d22 --- /dev/null +++ b/zsh/.config/zsh/functions.zsh @@ -0,0 +1,59 @@ +# 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 +} + +# 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/zsh/.zshrc b/zsh/.zshrc new file mode 100644 index 0000000..f4754a7 --- /dev/null +++ b/zsh/.zshrc @@ -0,0 +1,19 @@ +# 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 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