Skip to content

Instantly share code, notes, and snippets.

@the-codinator
Last active September 25, 2023 18:37
Show Gist options
  • Save the-codinator/5cea1a5a1799aa3b4aa2183413f89d31 to your computer and use it in GitHub Desktop.
Save the-codinator/5cea1a5a1799aa3b4aa2183413f89d31 to your computer and use it in GitHub Desktop.
Some good to have configs for bash (or zsh) for your terminal
###################
##### SOURCES #####
###################
##### Aliases #####
## Git
export GH_HOST=github.com
function clone { [[ -z "$1" ]] && echo "Error: Missing repo name parameter" && return 2; local git_org=$(basename $(pwd)); echo "Cloning [$git_org/$1] ..."; git clone "git@$GH_HOST:$git_org/$1.git"; }
alias glog="git log --pretty=oneline --abbrev-commit"
alias gs="git status --short --branch"
alias gfix="git commit -a --amend --no-edit"
## CLI utils
alias sl=ls
alias ll='ls -lah'
alias docker-prune='docker system prune --all --volumes --force'
alias az-token="az account get-access-token | jq -r '.accessToken'"
alias vault-login="vault login -method=ldap username=${ARTIFACTORY_USER}"
alias img2txt='pngpaste - | tesseract - -' # read text from copied image/screenshot on clipboard
## Applications
alias subl="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"
alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladmin
################
##### Exports #####
export KUBECONFIG=~/.kube/config
export SBT_OPTS="-XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=2G -Xmx2G"
export AWS_CLI_AUTO_PROMPT=on
export PATH=$PATH:~/bin
################
##### Auto Completion #####
## ZSH setup
autoload bashcompinit && bashcompinit
autoload -Uz compinit && compinit
compinit
# Note: most tools installed using Homebrew or globally have their auto completions configs already installed
# in the global directory (/etc/bash_completion.d) or in the user local directory (/usr/local/etc/bash_completion.d)
# The above commands automatically load auto-completions from these directories
## Additional Completions
complete -C $(which aws_completer) aws # AWS CLI
source /usr/local/etc/bash_completion.d/az # Azure CLI -> For some stupid reason this does automatically get picked up
################
##### OS Specific Stuff #####
# Primarily contains clipboard & file manager utilities
function windows {
alias pbcopy=clip
alias pbpaste="powershell.exe Get-Clipboard | sed 's/\r$//' | sed -z '$ s/\n$//'"
}
function linux {
alias pbcopy='xsel --clipboard --input'
alias pbpaste='xsel --clipboard --output'
alias explorer=xdg-open
}
function macos {
alias clip=pbcopy
alias explorer=open
}
case "$OSTYPE" in
msys*|cygwin*) windows ;;
linux*) linux ;;
solaris*|bsd*) linux ;;
darwin*) macos ;;
*) echo "Unknown OS for OS specific configs" >&2 ;;
esac
################
# Additional source files can be added for: global secrets & configs, VM aliases, etc
#########################
##### SHELL CONFIGS #####
#########################
##### INPUTRC (.inputrc) #####
## arrow up
"\e[A":history-search-backward
## arrow down
"\e[B":history-search-forward
################
##### ZSH (.zshrc) #####
## AUTO LOAD SOURCES
SOURCES_DIR=".sources"
[ -d ~/$SOURCES_DIR ] && for f in ~/$SOURCES_DIR/*; do source "$f"; done
## BINDINGS
# Ref: https://superuser.com/questions/585003/searching-through-history-with-up-and-down-arrow-in-zsh/585004
autoload -U up-line-or-beginning-search
autoload -U down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
bindkey "${terminfo[kcuu1]}" up-line-or-beginning-search
bindkey "${terminfo[kcud1]}" down-line-or-beginning-search
bindkey "^R" history-incremental-search-backward
## HISTORY
setopt HIST_FIND_NO_DUPS
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_SPACE
# setopt SHARE_HISTORY
################
@the-codinator
Copy link
Author

Note: Some of these commands are specific to MacOS / zsh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment