Major revamp of shell init - drop bash support, focus on zsh

This commit is contained in:
2018-07-20 00:46:33 +01:00
parent 582a97c7af
commit a53788f5c4
39 changed files with 210 additions and 649 deletions

106
zsh/aliases.zsh Normal file
View File

@@ -0,0 +1,106 @@
#
# Aliases
#
# System
alias o="open"
alias s="ssh"
alias ec="echo"
alias ls="ls -B"
alias l="ls -lah"
alias ll="ls -lah"
alias duh="du -h"
# Helpers
alias reload="source ~/.profile"
# Editors
alias n="nano"
alias t="mate"
alias e="$DOTBIN/emacsclient-wrapper"
alias eg="$DOTBIN/emacs-gui-client"
alias egs="$DOTBIN/emacs-gui-server"
# Utils
alias ma="make"
alias br="brew"
alias ca="brew cask"
alias cask="brew cask"
alias di="colordiff"
alias devnullsmtp="java -jar $DOTBIN/DevNullSmtp.jar"
alias open_ports="sudo lsof -i -P | grep --color=never -i \"listen\""
# Ansible
alias ap="ansible-playbook"
alias av="ansible-vault"
# Flush DNS cache
alias flush_dns="dscacheutil -flushcache"
# Misc.
alias weechat="TERM=screen-256color weechat-curses"
alias slashdot="ab -kc 50 -t 300"
alias digg="ab -kc 50 -t 30"
alias fact="elinks -dump randomfunfacts.com | sed -n '/^| /p' | tr -d \|"
alias netlisteners='lsof -i -P | grep LISTEN'
alias servethis="python -c 'import SimpleHTTPServer; SimpleHTTPServer.test()'"
alias lr='ls -R | grep ":$" | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\'''
alias fku="fuck you"
alias fucking="sudo"
# Improved myip alias. Echoed to avoid strange character at end in ZSH.
myip() {
echo "$(curl -s whatismyip.akamai.com)"
}
# appends your key to a server's authorized keys file
authme() {
ssh "$1" 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys' \
< ~/.ssh/id_rsa.pub
}
# ssh commands related to old SSH keys
alias ssho="ssh -i ~/.ssh/old-id_rsa"
authmeo() {
ssh -i ~/.ssh/old-id_rsa "$1" \
'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys' \
< ~/.ssh/id_rsa.pub
}
# Make and cd into directory
# - from: http://alias.sh/make-and-cd-directory
mcd() {
mkdir -p "$1" && cd "$1";
}
# Open man page in Preview.
pman () {
man -t "${1}" | open -f -a /Applications/Preview.app
}
# Extract most common archives with single command.
# - from: http://alias.sh/extract-most-know-archives-one-command
extract() {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.tar.xz) tar xvJf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tbz) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.txz) tar xvJf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
alias ext=extract

11
zsh/docker.zsh Normal file
View File

@@ -0,0 +1,11 @@
#
# Docker Related
#
alias d="docker"
alias dc="docker-compose"
alias co="docker-compose"
docker_remove_exited () {
docker rm $(docker ps -f="status=exited" -q)
}

17
zsh/emacs.zsh Normal file
View File

@@ -0,0 +1,17 @@
#
# Emacs
#
# OS X systems.
if [ -f "/Applications/Emacs.app/Contents/MacOS/Emacs" ]; then
alias emacs="/Applications/Emacs.app/Contents/MacOS/Emacs -nw"
fi
if [ -f "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient" ]; then
alias emacsclient="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient"
fi
# *nix systems.
if [ -d "/opt/emacs/bin" ]; then
path_append "/opt/emacs/bin"
fi

31
zsh/git.zsh Executable file
View File

@@ -0,0 +1,31 @@
#
# Git
#
# Aliases
alias g="git"
alias gi="git"
alias ga="git add"
alias gb="git branch"
alias gc="git checkout"
alias gcb="git checkout -b"
alias gr="git remote"
alias gs="git status"
alias gai="git add -i"
alias gp="git push"
alias gf="git fetch"
alias gd="git difftool"
alias gpl="git pull --rebase"
alias gix="gitx"
alias gx="gitx"
# Git Completion
if [ -n "$BASH_VERSION" ]; then
if [ -f "/usr/local/etc/bash_completion.d/git-completion.bash" ]; then
source "/usr/local/etc/bash_completion.d/git-completion.bash"
fi
# Only needed for Bash. Zsh is much smarter with it's auto-completion ^_^
complete -o default -o nospace -F _git g
complete -o default -o nospace -F _git gi
fi

38
zsh/golang.zsh Executable file
View File

@@ -0,0 +1,38 @@
#
# Go (golang) environment setup.
#
export GOPATH="$HOME/.go:$HOME/Projects/Go"
path_prepend "$HOME/.go/bin"
path_prepend "$HOME/Projects/Go/bin"
# aliases
alias gv="govendor"
install_go_global_packages () {
local packages=(
github.com/alecthomas/gometalinter
github.com/asciimoo/wuzz
github.com/derekparker/delve/cmd/dlv
github.com/golang/lint/golint
github.com/kisielk/errcheck
github.com/kr/pretty
github.com/mdempsky/unconvert
github.com/nsf/gocode
github.com/rakyll/hey
github.com/rogpeppe/godef
github.com/spf13/cobra/cobra
github.com/vektra/mockery/.../
golang.org/x/tools/cmd/godoc
golang.org/x/tools/cmd/goimports
golang.org/x/tools/cmd/gorename
golang.org/x/tools/cmd/guru
)
for package in "${packages[@]}"; do
echo "installing/updating \"$package\""
go get -u "$package"
done
gometalinter --install
}

7
zsh/google-cloud.zsh Normal file
View File

@@ -0,0 +1,7 @@
#
# Google Cloud SDK setup.
#
if [ -f '/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc' ]; then
source '/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc'
fi

13
zsh/kubernetes.zsh Normal file
View File

@@ -0,0 +1,13 @@
#
# Kubernetes Related
#
alias kc="kubectl"
alias hl="helm"
alias mk="minikube"
export KUBECONFIG="$HOME/.kube/config:.kube/config"
if command -v kubectl > /dev/null; then
eval "$(kubectl completion zsh)"
fi

11
zsh/less.zsh Normal file
View File

@@ -0,0 +1,11 @@
#
# less setup
#
alias le="less"
# Enable syntax highlighting via source-highlight
if command -v src-hilite-lesspipe.sh > /dev/null; then
export LESSOPEN="| src-hilite-lesspipe.sh %s"
export LESS=" -R "
fi

8
zsh/linux.zsh Normal file
View File

@@ -0,0 +1,8 @@
#
# Linux specific setup
#
# Ensure 256 color support in Linux
if [[ "$(uname)" == "Linux" ]]; then
export TERM="xterm-256color"
fi

40
zsh/nodejs.zsh Executable file
View File

@@ -0,0 +1,40 @@
#
# Node.js
#
# Aliases
alias no="node"
alias np="npm"
alias ni="npm install"
alias ngi="npm install -g"
alias cof="coffee"
alias tl="tldr"
install_node_global_packages () {
npm install -g \
eslint \
eslint-config-prettier \
eslint-plugin-prettier \
eslint_d \
htmllint-cli \
httpsnippet \
jsonlint \
localtunnel \
markdown-it \
prettier \
tldr \
tslint \
typescript \
typescript-formatter \
uuid-cli
}
# Load nvm if it's available
if [ -f "$HOME/.nvm/nvm.sh" ]; then
source "$HOME/.nvm/nvm.sh"
# And it's shell completion
if [ -n "$BASH_VERSION" ] && [ -f "$HOME/.nvm/bash_completion" ]; then
source "$HOME/.nvm/bash_completion"
fi
fi

41
zsh/osx.zsh Normal file
View File

@@ -0,0 +1,41 @@
#
# OSX Related
#
if [[ "$(uname)" == "Darwin" ]]; then
# Fix wifi issues on OS X 10.10.x Yosemite.
# - from: https://medium.com/@mariociabarra/wifried-ios-8-wifi-performance-issues-3029a164ce94
alias fix_wifi="sudo ifconfig awdl0 down"
alias unfix_wifi="sudo ifconfig awdl0 up"
# Disable the system built-in cmd+ctrl+d global hotkey to lookup word in
# dictionary on OS X. Must reboot after running.
# - from: ://apple.stackexchange.com/a/114269
osx-disable-lookup-word-hotkey() {
defaults write com.apple.symbolichotkeys AppleSymbolicHotKeys -dict-add 70 \
'<dict><key>enabled</key><false/></dict>'
echo "Command-Control-D hotkey disabled. Please reboot to take effect."
}
# Show hidden files in Finder.
show_files() {
defaults write com.apple.finder AppleShowAllFiles YES
killall Finder "/System/Library/CoreServices/Finder.app"
}
# Don't show hidden files in Finder.
hide_files() {
defaults write com.apple.finder AppleShowAllFiles NO
killall Finder "/System/Library/CoreServices/Finder.app"
}
# Power management
alias pm-hibernate="sudo pmset -a hibernatemode 25"
alias pm-safesleep="sudo pmset -a hibernatemode 3"
alias pm-sleep="sudo pmset -a hibernatemode 0"
hibernate() {
sudo pmset -a hibernatemode 25
sudo pmset sleepnow
}
fi

156
zsh/path_helpers.zsh Normal file
View File

@@ -0,0 +1,156 @@
#
# PATH Helpers
#
# A few useful functions to manipulate the PATH environment variable. Use,
# modify, copy, steal, plunder these functions to your hearts content, at
# your own risk of course :) --jimeh
#
# Print PATH as a newline separated list.
#
# Example:
#
# $ echo $PATH
# /usr/bin:/usr/local/bin
# $ path_list
# /usr/bin
# /usr/local/bin
#
path_list () {
echo -e ${PATH//:/\\n}
}
# Append specified path to the end of PATH.
#
# Takes one argument:
# - $1: path to add
#
# If $1 already exists it is first removed, and then added to the end of PATH.
#
# Example:
#
# $ echo $PATH
# /usr/bin:/usr/local/bin
# $ path_append "/usr/sbin"
# $ echo $PATH
# /usr/bin:/usr/local/bin:/usr/sbin
#
path_append () {
if [ ! -n "$1" ]; then return 2; fi
path_remove $1
export PATH="$PATH:$1"
}
# Prepend specified path to the begnning of PATH.
#
# Takes one argument:
# - $1: path to add
#
# If $1 already exists it is first removed, and then added to the beginning of
# PATH.
#
# Example:
#
# $ echo $PATH
# /usr/bin:/usr/local/bin
# $ path_prepend "/usr/sbin"
# $ echo $PATH
# /usr/sbin:/usr/bin:/usr/local/bin
#
path_prepend () {
if [ ! -n "$1" ]; then return 2; fi
path_remove $1
export PATH="$1:$PATH"
}
# Remove specified path from PATH.
#
# Takes one argument:
# - $1: path to remove
#
# Example:
#
# $ echo $PATH
# /usr/bin:/usr/local/bin
# $ path_remove "/usr/local/bin"
# $ echo $PATH
# /usr/bin
#
path_remove () {
if [ ! -n "$1" ]; then return 2; fi
if [[ ":$PATH:" == *":$1:"* ]]; then
local dirs=":$PATH:"
dirs=${dirs/:$1:/:}
export PATH="$(__path_clean $dirs)"
return 0
fi
return 1
}
# Add a path to PATH before another path.
#
# Takes two arguments:
# - $1: path to add
# - $2: target path to add $1 before
#
# If $1 already exists in PATH it is first removed, and then added before $2.
#
# Example:
#
# $ echo $PATH
# /usr/bin:/usr/local/bin
# $ path_add_before "/usr/local/sbin" "/usr/local/bin"
# $ echo $PATH
# /usr/bin:/usr/local/sbin:/usr/local/bin
#
path_add_before () {
if [ ! -n "$1" ] || [ ! -n "$2" ]; then return 2; fi
if [[ ":$PATH:" == *":$2:"* ]]; then
path_remove $1
local dirs=":$PATH:"
dirs=${dirs/:$2:/:$1:$2:}
export PATH="$(__path_clean $dirs)"
return 0
fi
return 1
}
# Add a path to PATH after another path.
#
# Takes two arguments:
# - $1: path to add
# - $2: target path to add $1 after
#
# If $1 already exists in PATH it is first removed, and then added after $2.
#
# Example:
#
# $ echo $PATH
# /usr/bin:/usr/local/bin
# $ path_add_after "/usr/local/sbin" "/usr/local/bin"
# $ echo $PATH
# /usr/bin:/usr/local/bin:/usr/local/sbin
#
path_add_after () {
if [ ! -n "$1" ] || [ ! -n "$2" ]; then return 2; fi
if [[ ":$PATH:" == *":$2:"* ]]; then
path_remove $1
local dirs=":$PATH:"
dirs=${dirs/:$2:/:$2:$1:}
export PATH="$(__path_clean $dirs)"
return 0
fi
return 1
}
# Strips first and last character from intput string.
#
# Example:
# $ __path_clean ":/bin:/usr/bin:"
# /bin:/usr/bin
#
__path_clean () {
local dirs=${1%?}
echo ${dirs#?}
}

68
zsh/ruby.zsh Executable file
View File

@@ -0,0 +1,68 @@
#
# Ruby environment setup.
#
install_ruby_global_packages () {
gem install --no-rdoc --no-ri \
bundler \
foreman \
lunchy \
method_source \
pry-doc \
rbenv-rehash \
reek \
rubocop \
seeing_is_believing \
travis
}
# Aliases
alias po="powify"
alias lu="lunchy"
alias he="heroku"
alias f="foreman"
alias fs="foreman start"
alias fr="foreman run"
# Aliases for specific ruby commands
alias ru="bundle exec ruby"
alias ra="bundle exec rake"
alias rai="bundle exec rails"
alias rs="bundle exec rspec"
alias cu="bundle exec cucumber"
alias scu="RAILS_ENV=cucumber bundle exec spring cucumber"
alias va="vagrant"
alias bc="bundle check"
alias bco="bundle console"
if [ -n "$BASH_VERSION" ]; then
# Bundler aliases
alias be="bundle exec"
alias bl="bundle list"
alias bp="bundle package"
alias bo="bundle open"
alias bu="bundle update"
alias bi="bundle_install"
alias bcn="bundle clean"
fi
# lazy-load rbenv
if [ -d "$HOME/.rbenv/shims" ]; then
path_prepend "$HOME/.rbenv/shims"
fi
rbenv() {
eval "$(command rbenv init -)"
rbenv "$@"
}
# lunchy auto-completion
if [ -n "$BASH_VERSION" ]; then
if which gem &> /dev/null && gem which lunchy &> /dev/null; then
LUNCHY_DIR="$(dirname "$(gem which lunchy)")/../extras"
if [ -f "$LUNCHY_DIR/lunchy-completion.bash" ]; then
source "$LUNCHY_DIR/lunchy-completion.bash"
fi
fi
fi

15
zsh/rust.zsh Normal file
View File

@@ -0,0 +1,15 @@
#
# Rust environment setup.
#
# Rustup
if [ -d "$HOME/.cargo/bin" ]; then
path_prepend "$HOME/.cargo/bin"
fi
install_rust_global_packages() {
rustup component add rustfmt-preview
rustup component add rust-src
cargo +nightly install --force clippy
cargo install --force racer
}

39
zsh/tmux.zsh Normal file
View File

@@ -0,0 +1,39 @@
# Aliases
alias tm="tmux"
alias tma="tm att"
alias tmn="tm new"
alias tml="tm ls"
alias tmm="tmn -s main"
# Custom Install
if [ -d "/opt/tmux/bin" ]; then
path_prepend "/opt/tmux/bin"
fi
# Tmux Completion
if [ -f "/usr/local/etc/bash_completion.d/tmux" ]; then
source "/usr/local/etc/bash_completion.d/tmux"
fi
# Tmuxifier
if [ -d "$DOTFILES/tmux/tmuxifier" ]; then
if [ -d "$DOTPFILES/tmux-layouts" ]; then
export TMUXIFIER_LAYOUT_PATH="$DOTPFILES/tmux-layouts"
else
export TMUXIFIER_LAYOUT_PATH="$HOME/.tmux-layouts"
fi
path_prepend "$DOTFILES/tmux/tmuxifier/bin"
eval "$(tmuxifier init -)"
alias m="tmuxifier"
alias ms="tmuxifier load-session"
alias mw="tmuxifier load-window"
alias mm="tmuxifier load-session main"
fi
use-tmuxifier-dev() {
path_prepend "$HOME/Projects/tmuxifier/bin"
path_remove "$DOTFILES/tmux/tmuxifier/bin"
export TMUXIFIER="$HOME/Projects/tmuxifier"
}

0
zsh/zplug/cache/.gitkeep vendored Normal file
View File

0
zsh/zplug/repos/.gitkeep Normal file
View File

1
zsh/zplug/zplug Submodule

Submodule zsh/zplug/zplug added at 15a59082c3