From 00d7b6ac208cafc9c1b8d68e9344cf8fb74b5eea Mon Sep 17 00:00:00 2001 From: connard <baptiste.gc@student-cs.fr> Date: Wed, 8 Jul 2020 21:43:20 +0200 Subject: [PATCH] add new plugin --- README.md | 11 ++++- plugins/watch/watch.plugin.zsh | 46 +++++++++++++++++++ .../oh-my-viarezo/functions}/prompt_utils.zsh | 0 .../oh-my-viarezo/functions}/utils.zsh | 0 .../oh-my-viarezo/functions}/vcs_themes.zsh | 0 .../oh-my-viarezo/functions}/vcs_utils.zsh | 0 .../oh-my-viarezo/test}/utils.zunit | 0 .../oh-my-viarezo/viarezo.zsh-theme | 0 8 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 plugins/watch/watch.plugin.zsh rename {functions => themes/oh-my-viarezo/functions}/prompt_utils.zsh (100%) rename {functions => themes/oh-my-viarezo/functions}/utils.zsh (100%) rename {functions => themes/oh-my-viarezo/functions}/vcs_themes.zsh (100%) rename {functions => themes/oh-my-viarezo/functions}/vcs_utils.zsh (100%) rename {test => themes/oh-my-viarezo/test}/utils.zunit (100%) rename viarezo.zsh-theme => themes/oh-my-viarezo/viarezo.zsh-theme (100%) diff --git a/README.md b/README.md index 0ba107c..54566ec 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,10 @@ This is a theme for ZSH which mainly forks the historical theme used on VIA Cent ## Install for Oh-My-ZSH -In order to use this theme, you have to clone this repository in your Oh-My-ZSH `custom/themes` directory (usually `~/.oh-my-zsh/custom/themes`): +In order to use this theme, you have to clone this repository in your Oh-My-ZSH `custom` directory (usually `~/.oh-my-zsh/custom`): ```shell -git clone https://gitlab.viarezo.fr/ViaRezo/oh-my-viarezo.git $ZSH/custom/themes/oh-my-viarezo +git clone https://gitlab.viarezo.fr/ViaRezo/oh-my-viarezo.git $ZSH/custom ``` You then need to select this theme in your `~/.zshrc` : @@ -32,6 +32,13 @@ You then need to select this theme in your `~/.zshrc` : ZSH_THEME="oh-my-viarezo/viarezo" ``` +To enable the custom plugin, juste add `watch` to the list of plugins in the `~/.zshrc`: + +```shell +plugins=(... watch) +``` + +The plugin will allow you to add `watch` in front of your last command by using `Ctrl+Esc`. ## Customization Time format defaults to `%D{%H:%M}`, but can be overwritten by setting the variable `OHMYVIAREZO_TIME_FORMAT` in your `~/.zshrc`. diff --git a/plugins/watch/watch.plugin.zsh b/plugins/watch/watch.plugin.zsh new file mode 100644 index 0000000..17fdcbf --- /dev/null +++ b/plugins/watch/watch.plugin.zsh @@ -0,0 +1,46 @@ +# ------------------------------------------------------------------------------ +# Description +# ----------- +# +# watch will be inserted before the command +# +# ------------------------------------------------------------------------------ +# Authors +# ------- +# +# * Connard <baptiste.gc@student-cs.fr> +# +# ------------------------------------------------------------------------------ + +watch-command-line() { + [[ -z $BUFFER ]] && LBUFFER="$(fc -ln -1)" +# if [[ -n $EDITOR && $BUFFER == $EDITOR\ * ]]; then +# if [[ ${#LBUFFER} -le ${#EDITOR} ]]; then +# RBUFFER=" ${BUFFER#$EDITOR }" +# LBUFFER="sudoedit" +# else +# LBUFFER="sudoedit ${LBUFFER#$EDITOR }" +# fi +# elif [[ $BUFFER == sudoedit\ * ]]; then +# if [[ ${#LBUFFER} -le 8 ]]; then +# RBUFFER=" ${BUFFER#sudoedit }" +# LBUFFER="$EDITOR" +# else +# LBUFFER="$EDITOR ${LBUFFER#sudoedit }" +# fi + if [[ $BUFFER == watch\ * ]]; then + if [[ ${#LBUFFER} -le 4 ]]; then + RBUFFER="${BUFFER#watch }" + LBUFFER="" + else + LBUFFER="${LBUFFER#watch }" + fi + else + LBUFFER="watch $LBUFFER" + fi +} +zle -N watch-command-line +# Defined shortcut keys: [Alt] [Esc] +bindkey -M emacs '^\e' watch-command-line +bindkey -M vicmd '^\e' watch-command-line +bindkey -M viins '^\e' watch-command-line diff --git a/functions/prompt_utils.zsh b/themes/oh-my-viarezo/functions/prompt_utils.zsh similarity index 100% rename from functions/prompt_utils.zsh rename to themes/oh-my-viarezo/functions/prompt_utils.zsh diff --git a/functions/utils.zsh b/themes/oh-my-viarezo/functions/utils.zsh similarity index 100% rename from functions/utils.zsh rename to themes/oh-my-viarezo/functions/utils.zsh diff --git a/functions/vcs_themes.zsh b/themes/oh-my-viarezo/functions/vcs_themes.zsh similarity index 100% rename from functions/vcs_themes.zsh rename to themes/oh-my-viarezo/functions/vcs_themes.zsh diff --git a/functions/vcs_utils.zsh b/themes/oh-my-viarezo/functions/vcs_utils.zsh similarity index 100% rename from functions/vcs_utils.zsh rename to themes/oh-my-viarezo/functions/vcs_utils.zsh diff --git a/test/utils.zunit b/themes/oh-my-viarezo/test/utils.zunit similarity index 100% rename from test/utils.zunit rename to themes/oh-my-viarezo/test/utils.zunit diff --git a/viarezo.zsh-theme b/themes/oh-my-viarezo/viarezo.zsh-theme similarity index 100% rename from viarezo.zsh-theme rename to themes/oh-my-viarezo/viarezo.zsh-theme -- GitLab