From 41b97a1be327732c662ef9202dfcfba7d398b411 Mon Sep 17 00:00:00 2001 From: bretello Date: Sat, 26 Mar 2022 13:35:54 +0100 Subject: [PATCH] zsh: refactor aliases/functions sourcing --- aliases/README.md | 4 ++++ aliases.zsh => aliases/aliases.zsh | 0 brethil_dotfile.sh | 14 +++++++++----- functions/README.md | 4 ++++ functions.zsh => functions/misc.zsh | 15 ++++++++++++++- 5 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 aliases/README.md rename aliases.zsh => aliases/aliases.zsh (100%) create mode 100644 functions/README.md rename functions.zsh => functions/misc.zsh (95%) diff --git a/aliases/README.md b/aliases/README.md new file mode 100644 index 0000000..20f4bbf --- /dev/null +++ b/aliases/README.md @@ -0,0 +1,4 @@ +# aliases + +Place custom alias definitions in this folder, with a `.zsh` extension. +These files will be sourced on startup diff --git a/aliases.zsh b/aliases/aliases.zsh similarity index 100% rename from aliases.zsh rename to aliases/aliases.zsh diff --git a/brethil_dotfile.sh b/brethil_dotfile.sh index 316fed6..8030be5 100755 --- a/brethil_dotfile.sh +++ b/brethil_dotfile.sh @@ -87,15 +87,19 @@ alias esource='$EDITOR $HOME/.zshrc' alias resource='source $HOME/.zshrc' alias dotedit='$EDITOR $DOTFILES/brethil_dotfile.sh' # Custom definitions files -alias funedit='$EDITOR ~/.dotfiles_functions.sh' -alias aledit='$EDITOR ~/.dotfiles_aliases.sh' +alias funedit='$EDITOR ~/.dotfiles_functions' +alias aledit='$EDITOR ~/.dotfiles_aliases' export p="${HOME}/projects" export g="${HOME}/git" -export w="${HOME}/work" -source $DOTFILES/functions.zsh -source $DOTFILES/aliases.zsh + +for defname in aliases functions ; do + for def in $DOTFILES/$defname/*zsh ; do + source $def + done +done +unset def defname # Extras functions_file=~/.dotfiles_functions diff --git a/functions/README.md b/functions/README.md new file mode 100644 index 0000000..0e34d99 --- /dev/null +++ b/functions/README.md @@ -0,0 +1,4 @@ +# functions + +Place custom functions definitions in this folder, with a `.zsh` extension. +These files will be sourced on startup diff --git a/functions.zsh b/functions/misc.zsh similarity index 95% rename from functions.zsh rename to functions/misc.zsh index ac0e9c6..7a0adc2 100755 --- a/functions.zsh +++ b/functions/misc.zsh @@ -275,6 +275,19 @@ __git_completion_wrapper() { __completion_wrapper $1 _git } + +# sort branches by latest commit +function git-sort-branch-by-usage(){ + git for-each-ref --sort=committerdate refs/heads/ --format='%(refname:short)' +} + +# switch to a recent branch +function git-switch-recent-branch(){ + git switch $1 +} +# compdef git-sort-branch-by-usage git-switch-recent-branch +compdef "__git_completion_wrapper __git_recent_branches" git-switch-recent-branch + # Runs git log with fzf with preview function fgitlog() { git log --oneline $@ | fzf --multi --preview 'git -p show --color=always {+1}' --preview-window=right,60% @@ -282,7 +295,7 @@ function fgitlog() { compdef _git fgitlog=git-log git-commit-show() { - git log --graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr" | + git log --graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr" $@ | fzf --ansi --no-sort --reverse --tiebreak=index --preview \ 'f() { set -- $(echo -- "$@" | grep -o "[a-f0-9]\{7\}")