From ff8f182b751d91ba284f33aa2e554f86c8413a72 Mon Sep 17 00:00:00 2001 From: Simon Let Date: Fri, 13 Dec 2019 15:50:29 +0100 Subject: [PATCH] fix issues with zsh and completions --- Makefile | 13 +++++++++---- cmd/control/cmd/completion.go | 10 +++++----- cmd/control/cmd/debug.go | 6 +++--- cmd/control/cmd/root.go | 3 +-- scripts/util.sh | 15 +++++++++++++-- 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index da01a7a..d1e28f3 100644 --- a/Makefile +++ b/Makefile @@ -82,15 +82,20 @@ install: build submodules/bash-preexec/bash-preexec.sh scripts/shellrc.sh conf/c [ ! -f ~/.resh/history.json ] || mv ~/.resh/history.json ~/.resh_history.json # Adding resh shellrc to .bashrc ... grep '[[ -f ~/.resh/shellrc ]] && source ~/.resh/shellrc' ~/.bashrc ||\ - echo '[[ -f ~/.resh/shellrc ]] && source ~/.resh/shellrc' >> ~/.bashrc + echo -e '\n[[ -f ~/.resh/shellrc ]] && source ~/.resh/shellrc' >> ~/.bashrc # Adding bash-preexec to .bashrc ... grep '[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' ~/.bashrc ||\ - echo '[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' >> ~/.bashrc + echo -e '\n[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' >> ~/.bashrc # Adding resh shellrc to .zshrc ... grep '[ -f ~/.resh/shellrc ] && source ~/.resh/shellrc' ~/.zshrc ||\ - echo '[ -f ~/.resh/shellrc ] && source ~/.resh/shellrc' >> ~/.zshrc + echo -e '\n[ -f ~/.resh/shellrc ] && source ~/.resh/shellrc' >> ~/.zshrc + @# Deleting zsh completion cache - for future use + @# [ ! -e ~/.zcompdump ] || rm ~/.zcompdump # Restarting resh daemon ... - -[ ! -f ~/.resh/resh.pid ] || kill -SIGTERM $$(cat ~/.resh/resh.pid) + -if [ ! -f ~/.resh/resh.pid ]; then\ + kill -SIGTERM $$(cat ~/.resh/resh.pid);\ + rm ~/.resh/resh.pid;\ + fi nohup resh-daemon &>/dev/null & disown # Reloading rc files . ~/.resh/shellrc diff --git a/cmd/control/cmd/completion.go b/cmd/control/cmd/completion.go index bf09a67..e80fa56 100644 --- a/cmd/control/cmd/completion.go +++ b/cmd/control/cmd/completion.go @@ -10,20 +10,20 @@ import ( // completionCmd represents the completion command var completionCmd = &cobra.Command{ Use: "completion", - Short: "Generates bash/zsh completion scripts", + Short: "generate bash/zsh completion scripts", Long: `To load completion run . <(reshctl completion bash) OR -. <(reshctl completion zsh) +. <(reshctl completion zsh) && compdef _reshctl reshctl `, } var completionBashCmd = &cobra.Command{ Use: "bash", - Short: "Generates bash completion scripts", + Short: "generate bash completion scripts", Long: `To load completion run . <(reshctl completion bash) @@ -36,10 +36,10 @@ var completionBashCmd = &cobra.Command{ var completionZshCmd = &cobra.Command{ Use: "zsh", - Short: "Generates zsh completion scripts", + Short: "generate zsh completion scripts", Long: `To load completion run -. <(reshctl completion zsh) +. <(reshctl completion zsh) && compdef _reshctl reshctl `, Run: func(cmd *cobra.Command, args []string) { rootCmd.GenZshCompletion(os.Stdout) diff --git a/cmd/control/cmd/debug.go b/cmd/control/cmd/debug.go index fc10550..1b43c54 100644 --- a/cmd/control/cmd/debug.go +++ b/cmd/control/cmd/debug.go @@ -12,13 +12,13 @@ import ( var debugCmd = &cobra.Command{ Use: "debug", - Short: "Debug utils for resh", + Short: "debug utils for resh", Long: "Reloads resh rc files. Shows logs and output from last runs of resh", } var debugReloadCmd = &cobra.Command{ Use: "reload", - Short: "Reload resh rc files", + Short: "reload resh rc files", Long: "Reload resh rc files", Run: func(cmd *cobra.Command, args []string) { exitCode = status.ReloadRcFiles @@ -27,7 +27,7 @@ var debugReloadCmd = &cobra.Command{ var debugOutputCmd = &cobra.Command{ Use: "output", - Short: "Shows output from last runs of resh", + Short: "shows output from last runs of resh", Long: "Shows output from last runs of resh", Run: func(cmd *cobra.Command, args []string) { files := []string{ diff --git a/cmd/control/cmd/root.go b/cmd/control/cmd/root.go index a9e4c50..a9bd514 100644 --- a/cmd/control/cmd/root.go +++ b/cmd/control/cmd/root.go @@ -11,8 +11,7 @@ var exitCode status.Code var rootCmd = &cobra.Command{ Use: "reshctl", - Short: "Reshctl (RESH control) - enables you to enable/disable features and more.", - Long: `Enables you to enable/disable RESH bindings for arrows and C-R.`, + Short: "Reshctl (RESH control) - enable/disable RESH features and more.", } // Execute reshctl diff --git a/scripts/util.sh b/scripts/util.sh index bbdceb4..23e365b 100644 --- a/scripts/util.sh +++ b/scripts/util.sh @@ -63,8 +63,19 @@ __resh_bash_completion_init() { } __resh_zsh_completion_init() { - # shellcheck disable=SC2206 - fpath=(~/.resh/zsh_completion.d $fpath) + # NOTE: this is hacky - each completion needs to be added individually + # TODO: fix later + # fpath=(~/.resh/zsh_completion.d $fpath) + # we should be using fpath but that doesn't work well with oh-my-zsh + # so we are just adding it manually + # shellcheck disable=1090 + source ~/.resh/zsh_completion.d/_reshctl && compdef _reshctl reshctl + + # TODO: test and use this + # NOTE: this is not how globbing works + # for f in ~/.resh/zsh_completion.d/_*; do + # source ~/.resh/zsh_completion.d/_$f && compdef _$f $f + # done } __resh_session_init() {