diff --git a/README.md b/README.md index 882c99a..45f113c 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,36 @@ curl -sS https://raw.githubusercontent.com/chvolkmann/code-connect/main/bash/uni Deletes the aliases from `~/.bashrc` and removes the folder `~/.code-connect` +### Zsh + +#### Installing + +With [Oh My Zsh](https://github.com/ohmyzsh/ohmyzsh) + +1. Clones the repository into `$ZSH_CUSTOM/plugins` (by default `~/.oh-my-zsh/custom/plugins`) + +```zsh +git clone https://github.com/chvolkmann/code-connect $ZSH_CUSTOM/plugins/code-connect +``` + +2. Add `code-connect` to the plugins array in your `.zshrc` file + +```zsh +plugins=(... code-connect) +``` + +#### Updating + +```zsh +git -C $ZSH_CUSTOM/plugins/code-connect pull +``` + +#### Uninstalling + +```zsh +rm -rf $ZSH_CUSTOM/plugins/code-connect +``` + ## Usage Use `code` as you would normally! diff --git a/code-connect.plugin.zsh b/code-connect.plugin.zsh new file mode 100644 index 0000000..3c85d90 --- /dev/null +++ b/code-connect.plugin.zsh @@ -0,0 +1,7 @@ +# Add the binary directory to user's path +PLUGIN_DIR="$(dirname $0)" +export PATH="${PATH}:${PLUGIN_DIR}/bin" + +# update fpath, and then lazy autoload files in the directory as functions +fpath=($PLUGIN_DIR/zsh_functions $fpath) +autoload -U code code-connect diff --git a/zsh_functions/code b/zsh_functions/code new file mode 100644 index 0000000..c28cfd6 --- /dev/null +++ b/zsh_functions/code @@ -0,0 +1,9 @@ +# The $commands arrays are described in the zsh/parameter module to access the internal hash tables. +# $+param expands to 0 if param is unset, and 1 if it's set. +if [[ ${+commands[code]} -eq 1 ]] ; then + # code is a command, use that binary instead of the code-connect + command code "$@" +else + # code not locally installed, use code-connect + code_connect.py "$@" +fi diff --git a/zsh_functions/code-connect b/zsh_functions/code-connect new file mode 100644 index 0000000..68c9f85 --- /dev/null +++ b/zsh_functions/code-connect @@ -0,0 +1 @@ +code_connect.py "$@"