fish: Move all functions to ~/.config/fish/functions
This commit is contained in:
parent
99482de9a4
commit
f5fd6ddd55
31 changed files with 123 additions and 157 deletions
|
@ -256,163 +256,6 @@ alias cbd='cargo doc'
|
|||
alias cbD='cargo doc --open'
|
||||
alias cbu='cargo update'
|
||||
|
||||
# Git fzf helper functions
|
||||
# https://github.com/junegunn/fzf/wiki/Examples-(fish)
|
||||
function fco -d "Checkout a branch using fzf"
|
||||
git branch --all | grep -v HEAD | string trim | fzf | read -l result; and git checkout "$result"
|
||||
end
|
||||
|
||||
function fcoc -d "Checkout a commit using fzf"
|
||||
git log --pretty=oneline --abbrev-commit --reverse | fzf --tac +s -e | awk '{print $1;}' | read -l result; and git checkout "$result"
|
||||
end
|
||||
|
||||
# https://gist.github.com/gabesoft/b6e5e959c4cb11ed257d41edb07d47cb
|
||||
# Modify to use --exact flag for fzf and delta as pager
|
||||
function fbr --description "Git browse commits"
|
||||
set -l log_line_to_hash "echo {} | grep -o '[a-f0-9]\{7\}' | head -1"
|
||||
set -l view_commit "$log_line_to_hash | xargs -I % sh -c 'git show --color=always % | delta | less -R'"
|
||||
set -l copy_commit_hash "$log_line_to_hash | xclip"
|
||||
set -l git_checkout "$log_line_to_hash | xargs -I % sh -c 'git checkout %'"
|
||||
set -l open_cmd "open"
|
||||
|
||||
if test (uname) = Linux
|
||||
set open_cmd "xdg-open"
|
||||
end
|
||||
|
||||
set github_open "$log_line_to_hash | xargs -I % sh -c '$open_cmd https://github.\$(git config remote.origin.url | cut -f2 -d. | tr \':\' /)/commit/%'"
|
||||
|
||||
git log --color=always --format='%C(auto)%h%d %s %C(green)%C(bold)%cr% C(blue)%an' | \
|
||||
fzf --exact --no-sort --reverse --tiebreak=index --no-multi --ansi \
|
||||
--preview="$view_commit" \
|
||||
--header="ENTER to view, CTRL-Y to copy hash, CTRL-O to open on GitHub, CTRL-X to checkout, CTRL-C to exit" \
|
||||
--bind "enter:execute:$view_commit" \
|
||||
--bind "ctrl-y:execute:$copy_commit_hash" \
|
||||
--bind "ctrl-x:execute:$git_checkout" \
|
||||
--bind "ctrl-o:execute:$github_open"
|
||||
end
|
||||
|
||||
function fcf --description "Git commit fixup using fzf"
|
||||
git commit --fixup (git log --pretty=oneline --abbrev-commit --color=always | fzf --ansi | cut -d ' ' -f1)
|
||||
end
|
||||
|
||||
function fcr --description "Git reset to a selected commit using fzf"
|
||||
git reset $argv (git log --pretty=oneline --abbrev-commit --color=always | fzf --ansi +s | awk '{print $1}')
|
||||
end
|
||||
|
||||
function fcR --description "Git revert a selected commit using fzf"
|
||||
git revert (git log --pretty=oneline --abbrev-commit --color=always | fzf --ansi +s | awk '{print $1}')
|
||||
end
|
||||
|
||||
function frbi --description "Git interactive rebase using fzf"
|
||||
git rebase -i (git log --pretty=oneline --abbrev-commit --color=always | fzf --ansi | cut -d ' ' -f1)
|
||||
end
|
||||
|
||||
function ffa --description "Git add files using fzf"
|
||||
git add -- (git ls-files --modified --others --exclude-standard | fzf -m --preview 'bat --color=always {}')
|
||||
end
|
||||
|
||||
function ffco --description "Git checkout a file using fzf"
|
||||
git checkout $argv -- (git ls-files --modified --exclude-standard | fzf -m)
|
||||
end
|
||||
|
||||
function ffrs --description "Git restore a staged file using fzf"
|
||||
git restore --staged $argv -- (git diff --name-only --staged | fzf -m)
|
||||
end
|
||||
|
||||
function ffr --description "Git restore a file using fzf"
|
||||
git restore $argv -- (git ls-files --modified --exclude-standard | fzf -m)
|
||||
end
|
||||
|
||||
function grf --description "Search within a file with grep with context"
|
||||
grep --color=always -C 10 --group-separator="---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" $argv | less -R
|
||||
end
|
||||
|
||||
function rgf --description "Search within a file with ripgrep"
|
||||
rg --color always $argv | nvim -R +AnsiEsc
|
||||
end
|
||||
|
||||
function rgc --description "Search within a file with ripgrep with context"
|
||||
rg --color always -C 10 --context-separator="---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" $argv | nvim -R +AnsiEsc
|
||||
end
|
||||
|
||||
function vo --description "Pipe a command output to neovim"
|
||||
$argv | nvim -R
|
||||
end
|
||||
|
||||
function dotp --description "Generate Pipewire dot graph for linked nodes"
|
||||
pw-dot -L -s -o /tmp/pw.dot
|
||||
dot -Tsvg /tmp/pw.dot > ~/Pictures/pipewire/pw-dot-(date +%T).svg
|
||||
rm /tmp/pw.dot
|
||||
end
|
||||
|
||||
function dotP --description "Generate Pipewire dot graph for all nodes"
|
||||
pw-dot -L -a -o /tmp/pw.dot
|
||||
dot -Tsvg /tmp/pw.dot > ~/Pictures/pipewire/pw-dot-(date +%T).svg
|
||||
rm /tmp/pw.dot
|
||||
end
|
||||
|
||||
function dotg --description "Generate gstreamer dot graph for selected file"
|
||||
find $argv -maxdepth 1 -regextype posix-extended -regex ".*\.(dot)" | fzf | read -l result; and dot -Tsvg "$result" -O
|
||||
mv "$result".svg ~/Pictures/gstreamer
|
||||
end
|
||||
|
||||
function gdba --description "Attach to a process"
|
||||
gdb attach -p (ps -ef | fzf | awk '{print $2}' | head -1)
|
||||
end
|
||||
|
||||
function gdbp --description "Attach to a python process"
|
||||
gdb python3 (ps -ef | fzf | awk '{print $2}' | head -1)
|
||||
end
|
||||
|
||||
function gdbr --description "Start a command/process with rust-gdb"
|
||||
rust-gdb --args $argv
|
||||
end
|
||||
|
||||
function pst --description "Show process tree of a process"
|
||||
set proc (ps -ef | fzf | awk '{print $2}' | head -1)
|
||||
pstree -H $proc $proc
|
||||
end
|
||||
|
||||
function cdi --description "Select a coredump to run coredumpctl info"
|
||||
coredumpctl list --reverse | awk -F" " '$9 == "present"' | fzf | read -l result
|
||||
coredumpctl info (echo $result | awk -F" " '{print $5}')
|
||||
end
|
||||
|
||||
function cdg --description "coredumpctl gdb on last crashed process"
|
||||
coredumpctl gdb
|
||||
end
|
||||
|
||||
function cdG --description "Select a coredump to run coredumpctl gdb"
|
||||
coredumpctl list --reverse | awk -F" " '$9 == "present"' | fzf | read -l result
|
||||
coredumpctl gdb (echo $result | awk -F" " '{print $5}')
|
||||
end
|
||||
|
||||
function pft --description "Select a process to run perf top"
|
||||
set proc (ps -ef | fzf | awk '{print $2}')
|
||||
perf top -p $proc
|
||||
end
|
||||
|
||||
function pfr --description "Select a process to record performance data in given file name"
|
||||
set proc (ps -ef | fzf | awk '{print $2}')
|
||||
perf record -F 99 -o $argv -p $proc
|
||||
end
|
||||
|
||||
function jbl --description "Select a boot to view logs"
|
||||
journalctl -r -b (journalctl --list-boots | fzf --tac | awk '{print $1}')
|
||||
end
|
||||
|
||||
function pk --description "Fuzzy find a process to kill"
|
||||
set proc (ps -ef | fzf | awk '{print $2}')
|
||||
kill -SIGKILL $proc
|
||||
end
|
||||
|
||||
function rfc --description "Search for string in RFC documents and open"
|
||||
if test -e ~/rfc
|
||||
rg --files-with-matches $argv ~/rfc | fzf | read -l result
|
||||
nvim -R $result
|
||||
end
|
||||
end
|
||||
|
||||
fzf_key_bindings
|
||||
|
||||
starship init fish | source
|
||||
|
|
4
fish/.config/fish/functions/cdG.fish
Normal file
4
fish/.config/fish/functions/cdG.fish
Normal file
|
@ -0,0 +1,4 @@
|
|||
function cdG --description 'Select a coredump to run coredumpctl gdb'
|
||||
coredumpctl list --reverse | awk -F" " '$9 == "present"' | fzf | read -l result
|
||||
coredumpctl gdb (echo $result | awk -F" " '{print $5}')
|
||||
end
|
3
fish/.config/fish/functions/cdg.fish
Normal file
3
fish/.config/fish/functions/cdg.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function cdg --description 'coredumpctl gdb on last crashed process'
|
||||
coredumpctl gdb
|
||||
end
|
4
fish/.config/fish/functions/cdi.fish
Normal file
4
fish/.config/fish/functions/cdi.fish
Normal file
|
@ -0,0 +1,4 @@
|
|||
function cdi --description 'Select a coredump to run coredumpctl info'
|
||||
coredumpctl list --reverse | awk -F" " '$9 == "present"' | fzf | read -l result
|
||||
coredumpctl info (echo $result | awk -F" " '{print $5}')
|
||||
end
|
5
fish/.config/fish/functions/dotP.fish
Normal file
5
fish/.config/fish/functions/dotP.fish
Normal file
|
@ -0,0 +1,5 @@
|
|||
function dotP --description 'Generate Pipewire dot graph for all nodes'
|
||||
pw-dot -L -a -o /tmp/pw.dot
|
||||
dot -Tsvg /tmp/pw.dot > ~/Pictures/pipewire/pw-dot-(date +%T).svg
|
||||
rm /tmp/pw.dot
|
||||
end
|
4
fish/.config/fish/functions/dotg.fish
Normal file
4
fish/.config/fish/functions/dotg.fish
Normal file
|
@ -0,0 +1,4 @@
|
|||
function dotg --description 'Generate gstreamer dot graph for selected file'
|
||||
find $argv -maxdepth 1 -regextype posix-extended -regex ".*\.(dot)" | fzf | read -l result; and dot -Tsvg "$result" -O
|
||||
mv "$result".svg ~/Pictures/gstreamer
|
||||
end
|
5
fish/.config/fish/functions/dotp.fish
Normal file
5
fish/.config/fish/functions/dotp.fish
Normal file
|
@ -0,0 +1,5 @@
|
|||
function dotp --description 'Generate Pipewire dot graph for linked nodes'
|
||||
pw-dot -L -s -o /tmp/pw.dot
|
||||
dot -Tsvg /tmp/pw.dot > ~/Pictures/pipewire/pw-dot-(date +%T).svg
|
||||
rm /tmp/pw.dot
|
||||
end
|
22
fish/.config/fish/functions/fbr.fish
Normal file
22
fish/.config/fish/functions/fbr.fish
Normal file
|
@ -0,0 +1,22 @@
|
|||
function fbr --description 'Git browse commits'
|
||||
set -l log_line_to_hash "echo {} | grep -o '[a-f0-9]\{7\}' | head -1"
|
||||
set -l view_commit "$log_line_to_hash | xargs -I % sh -c 'git show --color=always % | delta | less -R'"
|
||||
set -l copy_commit_hash "$log_line_to_hash | xclip"
|
||||
set -l git_checkout "$log_line_to_hash | xargs -I % sh -c 'git checkout %'"
|
||||
set -l open_cmd "open"
|
||||
|
||||
if test (uname) = Linux
|
||||
set open_cmd "xdg-open"
|
||||
end
|
||||
|
||||
set github_open "$log_line_to_hash | xargs -I % sh -c '$open_cmd https://github.\$(git config remote.origin.url | cut -f2 -d. | tr \':\' /)/commit/%'"
|
||||
|
||||
git log --color=always --format='%C(auto)%h%d %s %C(green)%C(bold)%cr% C(blue)%an' | \
|
||||
fzf --exact --no-sort --reverse --tiebreak=index --no-multi --ansi \
|
||||
--preview="$view_commit" \
|
||||
--header="ENTER to view, CTRL-Y to copy hash, CTRL-O to open on GitHub, CTRL-X to checkout, CTRL-C to exit" \
|
||||
--bind "enter:execute:$view_commit" \
|
||||
--bind "ctrl-y:execute:$copy_commit_hash" \
|
||||
--bind "ctrl-x:execute:$git_checkout" \
|
||||
--bind "ctrl-o:execute:$github_open"
|
||||
end
|
3
fish/.config/fish/functions/fcR.fish
Normal file
3
fish/.config/fish/functions/fcR.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function fcR --description 'Git revert a selected commit using fzf'
|
||||
git revert (git log --pretty=oneline --abbrev-commit --color=always | fzf --ansi +s | awk '{print $1}')
|
||||
end
|
3
fish/.config/fish/functions/fcf.fish
Normal file
3
fish/.config/fish/functions/fcf.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function fcf --description 'Git commit fixup using fzf'
|
||||
git commit --fixup (git log --pretty=oneline --abbrev-commit --color=always | fzf --ansi | cut -d ' ' -f1)
|
||||
end
|
3
fish/.config/fish/functions/fco.fish
Normal file
3
fish/.config/fish/functions/fco.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function fco --description 'Checkout a branch using fzf'
|
||||
git branch --all | grep -v HEAD | string trim | fzf | read -l result; and git checkout "$result"
|
||||
end
|
3
fish/.config/fish/functions/fcoc.fish
Normal file
3
fish/.config/fish/functions/fcoc.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function fcoc --description 'Checkout a commit using fzf'
|
||||
git log --pretty=oneline --abbrev-commit --reverse | fzf --tac +s -e | awk '{print $1;}' | read -l result; and git checkout "$result"
|
||||
end
|
3
fish/.config/fish/functions/fcr.fish
Normal file
3
fish/.config/fish/functions/fcr.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function fcr --description 'Git reset to a selected commit using fzf'
|
||||
git reset $argv (git log --pretty=oneline --abbrev-commit --color=always | fzf --ansi +s | awk '{print $1}')
|
||||
end
|
3
fish/.config/fish/functions/ffa.fish
Normal file
3
fish/.config/fish/functions/ffa.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function ffa --description 'Git add files using fzf'
|
||||
git add -- (git ls-files --modified --others --exclude-standard | fzf -m --preview 'bat --color=always {}')
|
||||
end
|
3
fish/.config/fish/functions/ffco.fish
Normal file
3
fish/.config/fish/functions/ffco.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function ffco --description 'Git checkout a file using fzf'
|
||||
git checkout $argv -- (git ls-files --modified --exclude-standard | fzf -m)
|
||||
end
|
3
fish/.config/fish/functions/ffr.fish
Normal file
3
fish/.config/fish/functions/ffr.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function ffr --description 'Git restore a file using fzf'
|
||||
git restore $argv -- (git ls-files --modified --exclude-standard | fzf -m)
|
||||
end
|
3
fish/.config/fish/functions/ffrs.fish
Normal file
3
fish/.config/fish/functions/ffrs.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function ffrs --description 'Git restore a staged file using fzf'
|
||||
git restore --staged $argv -- (git diff --name-only --staged | fzf -m)
|
||||
end
|
3
fish/.config/fish/functions/frbi.fish
Normal file
3
fish/.config/fish/functions/frbi.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function frbi --description 'Git interactive rebase using fzf'
|
||||
git rebase -i (git log --pretty=oneline --abbrev-commit --color=always | fzf --ansi | cut -d ' ' -f1)
|
||||
end
|
3
fish/.config/fish/functions/gdba.fish
Normal file
3
fish/.config/fish/functions/gdba.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function gdba --description 'Attach to a process'
|
||||
gdb attach -p (ps -ef | fzf | awk '{print $2}' | head -1)
|
||||
end
|
3
fish/.config/fish/functions/gdbp.fish
Normal file
3
fish/.config/fish/functions/gdbp.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function gdbp --description 'Attach to a python process'
|
||||
gdb python3 (ps -ef | fzf | awk '{print $2}' | head -1)
|
||||
end
|
3
fish/.config/fish/functions/gdbr.fish
Normal file
3
fish/.config/fish/functions/gdbr.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function gdbr --description 'Start a command/process with rust-gdb'
|
||||
rust-gdb --args $argv
|
||||
end
|
3
fish/.config/fish/functions/grf.fish
Normal file
3
fish/.config/fish/functions/grf.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function grf --description 'Search within a file with grep with context'
|
||||
grep --color=always -C 10 --group-separator="---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" $argv | less -R
|
||||
end
|
3
fish/.config/fish/functions/jbl.fish
Normal file
3
fish/.config/fish/functions/jbl.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function jbl --description 'Select a boot to view logs'
|
||||
journalctl -r -b (journalctl --list-boots | fzf --tac | awk '{print $1}')
|
||||
end
|
4
fish/.config/fish/functions/pfr.fish
Normal file
4
fish/.config/fish/functions/pfr.fish
Normal file
|
@ -0,0 +1,4 @@
|
|||
function pfr --description 'Select a process to record performance data in given file name'
|
||||
set proc (ps -ef | fzf | awk '{print $2}')
|
||||
perf record -F 99 -o $argv -p $proc
|
||||
end
|
4
fish/.config/fish/functions/pft.fish
Normal file
4
fish/.config/fish/functions/pft.fish
Normal file
|
@ -0,0 +1,4 @@
|
|||
function pft --description 'Select a process to run perf top'
|
||||
set proc (ps -ef | fzf | awk '{print $2}')
|
||||
perf top -p $proc
|
||||
end
|
4
fish/.config/fish/functions/pk.fish
Normal file
4
fish/.config/fish/functions/pk.fish
Normal file
|
@ -0,0 +1,4 @@
|
|||
function pk --description 'Fuzzy find a process to kill'
|
||||
set proc (ps -ef | fzf | awk '{print $2}')
|
||||
kill -SIGKILL $proc
|
||||
end
|
4
fish/.config/fish/functions/pst.fish
Normal file
4
fish/.config/fish/functions/pst.fish
Normal file
|
@ -0,0 +1,4 @@
|
|||
function pst --description 'Show process tree of a process'
|
||||
set proc (ps -ef | fzf | awk '{print $2}' | head -1)
|
||||
pstree -H $proc $proc
|
||||
end
|
6
fish/.config/fish/functions/rfc.fish
Normal file
6
fish/.config/fish/functions/rfc.fish
Normal file
|
@ -0,0 +1,6 @@
|
|||
function rfc --description 'Search for string in RFC documents and open'
|
||||
if test -e ~/rfc
|
||||
rg --files-with-matches $argv ~/rfc | fzf | read -l result
|
||||
nvim -R $result
|
||||
end
|
||||
end
|
3
fish/.config/fish/functions/rgc.fish
Normal file
3
fish/.config/fish/functions/rgc.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function rgc --description 'Search within a file with ripgrep with context'
|
||||
rg --color always -C 10 --context-separator="---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" $argv | nvim -R +AnsiEsc
|
||||
end
|
3
fish/.config/fish/functions/rgf.fish
Normal file
3
fish/.config/fish/functions/rgf.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function rgf --description 'Search within a file with ripgrep'
|
||||
rg --color always $argv | nvim -R +AnsiEsc
|
||||
end
|
3
fish/.config/fish/functions/vo.fish
Normal file
3
fish/.config/fish/functions/vo.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function vo --description 'Pipe a command output to neovim'
|
||||
$argv | nvim -R
|
||||
end
|
Loading…
Reference in a new issue