mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 06:12:34 +00:00
Zsh setup script and organization
This commit is contained in:
32
zsh/config/zsh-functions
Normal file
32
zsh/config/zsh-functions
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/bin/zsh
|
||||
# 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}"
|
||||
}
|
||||
Reference in New Issue
Block a user