Last active
August 24, 2023 18:36
-
-
Save simonrad/d1710308eef5209a1b22b923ff4fb383 to your computer and use it in GitHub Desktop.
My zshrc shell setup file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Set up custom zsh command prompt. | |
| PROMPT='%(?.%F{green}√.%F{red}%?)%f %B%F{240}%1~%f%b %# ' | |
| # Aliases. | |
| alias l='ls -G' | |
| alias la='l -a' | |
| alias ll='l -l' | |
| alias lla='l -la' | |
| alias b='cd ..' | |
| alias pec='echo $?' # print exit code | |
| alias sumlines='pbpaste | python3 -c "import sys; print(float(\"%.14g\" % (sum(float(line) for line in sys.stdin.read().splitlines() if line.strip()))))"' | |
| alias g='git' | |
| alias gd='echo; git branch; echo; git status; git --no-pager diff' | |
| alias gds='git --no-pager diff --staged' | |
| alias gitnp='git --no-pager' | |
| alias gnp='git --no-pager' | |
| alias gsu='git submodule update --init' | |
| alias gitsha='git rev-parse --verify HEAD' | |
| alias gpr='git pull --rebase' | |
| alias gca='git commit --amend' | |
| alias gcan='git commit --amend --no-edit' | |
| alias gs='git stash' | |
| alias gss='git show --stat' | |
| alias gb='git branch' | |
| alias gbv='git branch -vv' | |
| alias gr='git log --decorate --oneline --graph --branches --remotes="*/master"' | |
| alias gra='git log --decorate --oneline --graph --all' | |
| alias gm='git checkout master && git pull && cleanup_branches' | |
| alias grep='grep --color' | |
| # Git helpers. | |
| alias get_current_git_branch_name='python3 -c "print(\"$(git symbolic-ref HEAD 2>/dev/null)\".split(\"/\",2)[-1] or \"!no_branch!\")"' | |
| alias publish_git_branch='git push -u origin $(get_current_git_branch_name)' | |
| alias delete_remote_git_branch='git push origin --delete' | |
| alias gitauthors='git ls-tree -r --name-only HEAD | xargs -n1 git blame --line-porcelain HEAD | grep "^author " | sort | uniq -c | sort -nr' | |
| alias cleanup_branches='g fetch --all --prune; git branch -vv | grep '\'': gone]'\'' | cut -c 3- | awk '\''{print $1}'\'' | xargs git branch -D' # Delete any local branches whose remote-tracking branch has been deleted | |
| # Git grep. | |
| function gg() { | |
| gitnp grep "$@" -- \ | |
| ":(exclude)vendor/*" \ | |
| ":(exclude)*.min.*" | |
| } | |
| # Increase zsh history size, and enable sharing history across terminals. | |
| HISTFILE="$HOME/.zsh_history" | |
| HISTSIZE=100000 | |
| SAVEHIST=100000 | |
| setopt share_history | |
| alias history='history 0' | |
| # Load git completion for zsh | |
| zstyle ':completion:*:*:git:*' script ~/.zsh/git-completion.bash | |
| fpath=(~/.zsh $fpath) | |
| autoload -Uz compinit && compinit | |
| # Override the ssh command with a function that copies a bashrc file to the remote machine before running bash. | |
| myssh(){ /usr/bin/ssh -l ubuntu -t $* "curl --silent --show-error 'https://gist.github.com/simonrad/997b6577b326398b2a38/raw' --output /tmp/ssh_override_bashrc_file && /bin/bash --rcfile /tmp/ssh_override_bashrc_file -i"; } | |
| # Pass aliases through sudo. | |
| alias sudo='sudo ' | |
| export EDITOR='nano -w' | |
| # export EDITOR='subl -nw' | |
| # Add the subl command to the PATH. | |
| export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH" | |
| # export PATH="/usr/local/bin:/usr/local/sbin:$PATH" | |
| # Enable magical cd abilities. | |
| setopt auto_cd | |
| cdpath=($HOME/src) | |
| # # Set up virtualenvwrapper. | |
| # export WORKON_HOME=$HOME/.virtualenvs | |
| # export PROJECT_HOME=$HOME/src | |
| # source /usr/local/bin/virtualenvwrapper.sh | |
| # Aliases to start and stop the Postgresql server manually. | |
| export PGDATA='/usr/local/var/postgres' | |
| export PGHOST=localhost | |
| alias pgstart='pg_ctl -D $PGDATA -l $PGDATA/server.log start' | |
| alias pgstop='pg_ctl -D $PGDATA stop -s -m fast' | |
| alias pgc='pg_ctl' | |
| # Function to run a command in a new iTerm tab/window. | |
| run_in_new_terminal() { | |
| TEMP_SCRIPT=`mktemp -t run_in_new_terminal` | |
| echo '#!/bin/zsh' >> $TEMP_SCRIPT | |
| echo "cd '$PWD'" >> $TEMP_SCRIPT | |
| echo "echo 'Running: $@'" >> $TEMP_SCRIPT | |
| echo "echo" >> $TEMP_SCRIPT | |
| echo "$@" >> $TEMP_SCRIPT | |
| echo "echo" >> $TEMP_SCRIPT | |
| echo "echo 'Done'" >> $TEMP_SCRIPT | |
| echo "read" >> $TEMP_SCRIPT | |
| chmod +x $TEMP_SCRIPT | |
| open -a iTerm.app $TEMP_SCRIPT | |
| } | |
| # Encryption / decryption utilities. | |
| # ---------------------------------- | |
| function set_password_for_encryption { | |
| echo "Please type your password:" | |
| export PASSWORD_FOR_ENCRYPTION=$(cat) | |
| echo "Your password is now \"$PASSWORD_FOR_ENCRYPTION\"." | |
| } | |
| function print_password_for_encryption { | |
| echo "Your password is \"$PASSWORD_FOR_ENCRYPTION\"." | |
| } | |
| function encrypt { | |
| if [ -z "$PASSWORD_FOR_ENCRYPTION" ]; then | |
| echo "Please set your password first, by running set_password_for_encryption" | |
| else | |
| # Reads plaintext from stdin. | |
| # Writes encrypted and base64-encoded cyphertext to stdout. | |
| openssl des -e -aes128 -k "$PASSWORD_FOR_ENCRYPTION" | base64 | |
| fi | |
| } | |
| function decrypt { | |
| if [ -z "$PASSWORD_FOR_ENCRYPTION" ]; then | |
| echo "Please set your password first, by running set_password_for_encryption" | |
| else | |
| # Reads encrypted and base64-encoded cyphertext from stdin. | |
| # Writes plaintext to stdout. | |
| base64 -D | openssl des -d -aes128 -k "$PASSWORD_FOR_ENCRYPTION" | |
| fi | |
| } | |
| # ---------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment