From 1af1306c2c710ffba80c7c033bcef30a36fba51d Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Sun, 20 Jun 2021 15:41:20 +0200 Subject: New zsh config inspired by Chris --- .config/zsh/functions | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .config/zsh/functions (limited to '.config/zsh/functions') diff --git a/.config/zsh/functions b/.config/zsh/functions new file mode 100644 index 0000000..ede0039 --- /dev/null +++ b/.config/zsh/functions @@ -0,0 +1,31 @@ +# Function to source files if they exist +function zsh_add_file() { + [ -f "$ZDOTDIR/$1" ] && source "$ZDOTDIR/$1" +} + +function zsh_add_plugin() { + PLUGIN_NAME=$(echo $1 | cut -d "/" -f 2) + if [ -d "$ZDOTDIR/plugins/$PLUGIN_NAME" ]; then + # For plugins + zsh_add_file "plugins/$PLUGIN_NAME/$PLUGIN_NAME.plugin.zsh" || \ + zsh_add_file "plugins/$PLUGIN_NAME/$PLUGIN_NAME.zsh" + else + git clone "https://github.com/$1.git" "$ZDOTDIR/plugins/$PLUGIN_NAME" + fi +} + +function zsh_add_completion() { + PLUGIN_NAME=$(echo $1 | cut -d "/" -f 2) + if [ -d "$ZDOTDIR/plugins/$PLUGIN_NAME" ]; then + # For completions + completion_file_path=$(ls $ZDOTDIR/plugins/$PLUGIN_NAME/_*) + fpath+="$(dirname "${completion_file_path}")" + zsh_add_file "plugins/$PLUGIN_NAME/$PLUGIN_NAME.plugin.zsh" + else + git clone "https://github.com/$1.git" "$ZDOTDIR/plugins/$PLUGIN_NAME" + fpath+=$(ls $ZDOTDIR/plugins/$PLUGIN_NAME/_*) + [ -f $ZDOTDIR/.zccompdump ] && $ZDOTDIR/.zccompdump + fi + completion_file="$(basename "${completion_file_path}")" + if [ "$2" = true ] && compinit "${completion_file:1}" +} -- cgit v1.2.3-70-g09d2