-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zfunctions.zsh
88 lines (77 loc) · 2.5 KB
/
.zfunctions.zsh
1
#!/usr/bin/env zsh# shellcheck shell=bashfunction findBigFiles() { find ~/Documents/ -size +100M -ls | sort -k7nr}function geoip() { curl ipinfo.io/$1}## FZF FUNCTIONS ### fo [FUZZY PATTERN] - Open the selected file with the default editor# - Bypass fuzzy finder if there's only one match (--select-1)# - Exit if there's no match (--exit-0)fo() { local files IFS=$'\n' files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0)) [[ -n "$files" ]] && ${EDITOR:-vim} "${files[@]}"}# fh [FUZZY PATTERN] - Search in command historyfh() { print -z $( ([ -n "$ZSH_NAME" ] && fc -l 1 || history) | fzf +s --tac | sed 's/ *[0-9]* *//')}# fbr [FUZZY PATTERN] - Checkout specified branch# Include remote branches, sorted by most recent commit and limited to 30fgb() { local branches branch branches=$(git for-each-ref --count=30 --sort=-committerdate refs/heads/ --format="%(refname:short)") && branch=$(echo "$branches" | fzf-tmux -d $(( 2 + $(wc -l <<< "$branches") )) +m) && git checkout $(echo "$branch" | sed "s/.* //" | sed "s#remotes/[^/]*/##")}# tm [SESSION_NAME | FUZZY PATTERN] - delete tmux session# Running `tm` will let you fuzzy-find a session mame to delete# Passing an argument to `ftm` will delete that session if it existsftmk() { if [ $1 ]; then tmux kill-session -t "$1"; return fi session=$(tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf --exit-0) && tmux kill-session -t "$session" || echo "No session found to delete."}# fuzzy grep via rg and open in vim with line numberfgr() { local file local line read -r file line <<<"$(rg --no-heading --line-number $@ | fzf -0 -1 | awk -F: '{print $1, $2}')" if [[ -n $file ]] then vim $file +$line fi}# fstash - easier way to deal with stashes# type fstash to get a list of your stashes# enter shows you the contents of the stash# ctrl-d shows a diff of the stash against your current HEAD# ctrl-b checks the stash out as a branch, for easier mergingfzstash() { local out q k sha while out=$( git stash list --pretty="%C(yellow)%h %>(14)%Cgreen%cr %C(blue)%gs" | fzf --ansi --no-sort --query="$q" --print-query \ --expect=ctrl-d,ctrl-b); do mapfile -t out <<< "$out" q="${out[0]}" k="${out[1]}" sha="${out[-1]}" sha="${sha%% *}" [[ -z "$sha" ]] && continue if [[ "$k" == 'ctrl-d' ]]; then git diff $sha elif [[ "$k" == 'ctrl-b' ]]; then git stash branch "stash-$sha" $sha break; else git stash show -p $sha fi done}