Skip to content

Instantly share code, notes, and snippets.

@jednano
Forked from gilesbowkett/gist:6f9fadb6c0867d42f75d
Last active February 19, 2023 18:05
Show Gist options
  • Save jednano/1deb357e54b3daf5856c to your computer and use it in GitHub Desktop.
Save jednano/1deb357e54b3daf5856c to your computer and use it in GitHub Desktop.
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
export PATH="/usr/local/opt/python/bin:$PATH"
export GPG_TTY=$(tty)
# export START="$HOME/a"
# if [[ $PWD == $HOME ]]; then
# cd $START
# fi
# alias ls='ls -F --color --show-control-chars'
# alias ls='ls -F --show-control-chars'
alias ll='ls -l'
# Windows aliases
alias cls="clear && printf '\e[3J'"
# alias dir='ls -F --color=always'
alias dir='ls -l'
alias del='rm'
alias deltree='rm -Rf'
alias edit='nano'
alias find='grep --color=auto -in'
alias rd='rmdir'
alias ren='mv'
alias md='mkdir'
alias n10="volta install node@10 && volta install npm@bundled"
alias n12="volta install node@12 && volta install npm@bundled"
alias n14="volta install node@14 && volta install npm@bundled"
alias n16="volta install node@16 && volta install npm@bundled"
alias n18="volta install node@18 && volta install npm@bundled"
# git commands
alias ga='git add'
alias gb='git branch'
alias gc='git commit'
alias gd='git diff'
alias gf='git fetch'
alias gm='git merge'
alias gr='git rebase'
alias gs='git status'
alias gt='git tag'
alias dt='git difftool'
alias mt='git mergetool'
alias cb='git branch --show-current'
alias co='git checkout'
alias sw='git switch'
# previous branch
alias pb='git switch @{-1}'
alias push='git push'
# Function aliases
alias sq=squash
function squash() {
git rebase -i HEAD~$1
}
alias kp=killport
killport() {
for port in "$@"; do
lsof -i tcp:$port | grep LISTEN | awk '{print $2}' | xargs kill -9
done;
}
# Functions
function watch() {
saveIFS="$IFS"
IFS='/' # <- delimiter
# Find test file via glob expression
files=`ls **/__tests__/$1.spec.t*`
# Split file path into parts
a=(${(s:/:)files})
# Clone a -> b
b=("${a[@]}")
# Remove __tests__
b[-2]=()
# Remove .spec.
b="${b[*]:s/.spec./.}"
rushx test --watch "${a[*]}" --collectCoverageOnlyFrom "${b[*]}"
IFS="$saveIFS"
}
function pull() {
if [[ $@ ]]; then
# Pass the args through to `git pull`
return $(git pull $@) 2>/dev/null
fi
# Get verbose branch info (includes tracking)
branch=$(git branch -vv | grep $(git branch --show-current))
# Extract tracking info
branch=${branch#*\[}
branch=${branch%%\]*}
branch=${branch%%:*}
remote=${branch%%/*}
branch=${branch#*/}
if [[ -z $remote && -z $branch ]]; then
# There is no tracking information for the current branch.
return $(git pull) 2>/dev/null
fi
# Fetch only the current branch from the tracked remote
git fetch $remote $branch
original_commit=$(git rev-parse HEAD)
git merge FETCH_HEAD
if [[ -a package-lock.json ]]; then
git diff --name-only $original_commit HEAD | grep package-lock.json && npm ci
else
git diff --name-only $original_commit HEAD | grep package.json && npm install
fi
}
function squash() {
git rebase -i HEAD~$1
}
function blam() {
push origin $(git branch --show-current) $@
}
# Load version control information
autoload -Uz vcs_info
precmd() { vcs_info }
# Format the vcs_info_msg_0_ variable
zstyle ':vcs_info:git:*' formats 'on branch %b'
# Set up the prompt (with git branch name)
setopt PROMPT_SUBST
PROMPT='${PWD/#$HOME/~} > '
RPROMPT=\$vcs_info_msg_0_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment