- Topgrade (update everything with one command):
brew install topgrade - fzf (fuzzy finder):
brew install fzf - Github cli (gh):
brew install gh. Log in on first use withgh auth login - Bat (modern pager):
brew install bat
- Zoxide (cd on steroids):
brew install zoxide. - Git delta (pretty diffs):
brew install git-delta. See docs for config: https://github.com/dandavison/delta - TLDR (terminal help/cheatsheet):
brew install tealdeer. Exampletldr ssh - EZA (modern ls):
brew install eza - HTTPie (modern curl):
brew install httpie. Exhttp leadvalidator.test - PV (progress viewer):
brew install pv.
# (g)it (c)heckout (b)ranch with fuzzy find
gcb() {
git rev-parse HEAD >/dev/null 2>&1 || return
local branch
branch=$(fzf-git-branch)
if [[ "$branch" = "" ]]; then
echo "No branch selected."
return
fi
# If branch name starts with 'remotes/' then it is a remote branch. By
# using --track and a remote branch name, it is the same as:
# git checkout -b branchName --track origin/branchName
if [[ "$branch" = 'remotes/'* ]]; then
git checkout --track $branch
else
git checkout $branch
fi
}
# Temporarily commit all changes as "wip"
wip() {
if output=$(git status --porcelain) && [ -z "$output" ]; then
echo "Working directory is clean"
return 0
else
git add -A
git commit -m "wip"
fi
}
# Check if latest commit is "wip"
iswip() {
local quiet=false
if [ "$1" = "-q" ]; then
quiet=true
fi
local last_non_wip_commit=$(git log --format='%H %s' | grep -v '^[0-9a-f]* wip$' | head -n 1)
local last_non_wip_commit_hash=$(echo "$last_non_wip_commit" | cut -d ' ' -f1)
local num_wip_commits=$(git log --format='%s' "$last_non_wip_commit_hash..HEAD" | grep -c '^wip$')
if [ "$num_wip_commits" -gt 0 ]; then
if [ "$quiet" = false ]; then
echo "Yes, $num_wip_commits wip commit(s) found:"
git log --oneline "${last_non_wip_commit_hash}..HEAD"
fi
return 0
else
if [ "$quiet" = false ]; then
echo "No wip commits found. Current HEAD:"
git log --oneline -1
fi
return 1
fi
}
# Reset to latest non-wip commit
unwip() {
if ! iswip -q; then
echo "No wip commits found before the current HEAD."
return 1
fi
local last_non_wip_commit=$(git log --format='%H %s' | grep -v '^[0-9a-f]* wip$' | head -n 1)
local last_non_wip_commit_hash=$(echo "$last_non_wip_commit" | cut -d ' ' -f1)
local last_non_wip_commit_message=$(echo "$last_non_wip_commit" | cut -d ' ' -f2-)
local num_wip_commits=$(git log --format='%s' "$last_non_wip_commit_hash..HEAD" | grep -c '^wip$')
echo "Will reset $num_wip_commits wip commit(s)."
echo "New HEAD: $last_non_wip_commit_message"
git reset "$last_non_wip_commit_hash"
}Github alias to navigate and checkout relevant PRs.
Open ~/.config/gh/config.yml and add to aliases:
aliases:
prs: '!GH_FORCE_TTY="100%" gh pr list --json number,title,author,updatedAt,headRefName --template ''{{range .}}{{tablerow (printf "%v" .number | autocolor "green") .title (.author.login | autocolor "yellow") (.headRefName | autocolor "green") (timeago .updatedAt)}}{{end}}'' | fzf --ansi $([ -n "$1" ] && echo --query $1) --preview ''GH_FORCE_TTY="100%" gh pr view {1}'' | cut -d'' '' -f1 | xargs --no-run-if-empty gh pr checkout'alias pa="php artisan"
alias phpd="XDEBUG_MODE=debug XDEBUG_SESSION=1 php"
# Like pa, but with xdebug enabled
alias pad="phpd artisan"# Create a temporary folder and cd to it
cdtmp() {
builtin cd "$(mktemp -d)" || exit
builtin pwd
}Add to .zshrc or .zshenv
# Default terminal editor
export EDITOR="nano"
# Default options til FZF
export FZF_DEFAULT_OPTS="--layout=reverse
--info=inline
--height=80%
--multi
--preview='([[ -f {} ]] && (bat --style=numbers --color=always {} || cat {})) || ([[ -d {} ]] && (tree -C {} | less)) || echo {} 2>/dev/null | head -n 200'
--color='hl:148,hl+:154,pointer:032,marker:010,bg+:237,gutter:008'
--prompt='∼ '
--pointer='▶'
--marker='✓'"