3 Commits eeb01c18c1 ... fa64758aea

Author SHA1 Message Date
  Marc Cornellà fa64758aea fix(vagrant-prompt): make `vagrant_prompt_info` generic for any state (#12782) 4 weeks ago
  Marc Cornellà 68d189cb35 fix(last-working-dir): save working directory more strictly (#11343) 4 weeks ago
  Marc Cornellà 45516ca1d8 docs(jsontools): document requirements 4 weeks ago

+ 11 - 0
plugins/jsontools/README.md

@@ -8,6 +8,17 @@ To use it, add `jsontools` to the plugins array in your zshrc file:
 plugins=(... jsontools)
 plugins=(... jsontools)
 ```
 ```
 
 
+## Requirements
+
+The plugin uses one of these tools to process JSON data, in the following order:
+
+- `node`
+- `python3`
+- `ruby`
+
+Any of these must be in `$PATH` before the plugin is loaded, otherwise the plugin exits
+prematurely and the functions will not be available.
+
 ## Usage
 ## Usage
 
 
 Usage is simple... just take your json data and pipe it into the appropriate jsontool:
 Usage is simple... just take your json data and pipe it into the appropriate jsontool:

+ 10 - 7
plugins/last-working-dir/last-working-dir.plugin.zsh

@@ -9,20 +9,23 @@ chpwd_last_working_dir() {
   [[ "$ZSH_SUBSHELL" -eq 0 ]] || return 0
   [[ "$ZSH_SUBSHELL" -eq 0 ]] || return 0
   # Add ".$SSH_USER" suffix to cache file if $SSH_USER is set and non-empty
   # Add ".$SSH_USER" suffix to cache file if $SSH_USER is set and non-empty
   local cache_file="$ZSH_CACHE_DIR/last-working-dir${SSH_USER:+.$SSH_USER}"
   local cache_file="$ZSH_CACHE_DIR/last-working-dir${SSH_USER:+.$SSH_USER}"
-  builtin pwd >| "$cache_file"
+  'builtin' 'echo' '-E' "$PWD" >| "$cache_file"
 }
 }
 
 
 # Changes directory to the last working directory
 # Changes directory to the last working directory
 lwd() {
 lwd() {
   # Add ".$SSH_USER" suffix to cache file if $SSH_USER is set and non-empty
   # Add ".$SSH_USER" suffix to cache file if $SSH_USER is set and non-empty
   local cache_file="$ZSH_CACHE_DIR/last-working-dir${SSH_USER:+.$SSH_USER}"
   local cache_file="$ZSH_CACHE_DIR/last-working-dir${SSH_USER:+.$SSH_USER}"
-  [[ -r "$cache_file" ]] && cd "$(cat "$cache_file")"
+  [[ -r "$cache_file" ]] && cd "$(<"$cache_file")"
 }
 }
 
 
 # Jump to last directory automatically unless:
 # Jump to last directory automatically unless:
-# - this isn't the first time the plugin is loaded
-# - it's not in $HOME directory
-[[ -n "$ZSH_LAST_WORKING_DIRECTORY" ]] && return
-[[ "$PWD" != "$HOME" ]] && return
+#
+# - This isn't the first time the plugin is loaded
+# - We're not in the $HOME directory (e.g. if terminal opened a different folder)
+[[ -z "$ZSH_LAST_WORKING_DIRECTORY" ]] || return
+[[ "$PWD" == "$HOME" ]] || return
 
 
-lwd 2>/dev/null && ZSH_LAST_WORKING_DIRECTORY=1 || true
+if lwd 2>/dev/null; then
+  ZSH_LAST_WORKING_DIRECTORY=1
+fi

+ 22 - 3
plugins/vagrant-prompt/README.md

@@ -17,11 +17,15 @@ To display Vagrant info on your prompt add the `vagrant_prompt_info` to the
 `$PROMPT` or `$RPROMPT` variable in your theme. Example:
 `$PROMPT` or `$RPROMPT` variable in your theme. Example:
 
 
 ```zsh
 ```zsh
-PROMPT='%{$fg[$NCOLOR]%}%B%n%b%{$reset_color%}:%{$fg[blue]%}%B%c/%b%{$reset_color%} $(vagrant_prompt_info)$(svn_prompt_info)$(git_prompt_info)%(!.#.$) '
+PROMPT="$PROMPT"' $(vagrant_prompt_info)'
+# or
+RPROMPT='$(vagrant_prompt_info)'
 ```
 ```
 
 
-`vagrant_prompt_info` makes use of some custom variables. This is an example
-definition:
+### Customization
+
+`vagrant_prompt_info` makes use of the following custom variables, which can be set in your
+`.zshrc` file:
 
 
 ```zsh
 ```zsh
 ZSH_THEME_VAGRANT_PROMPT_PREFIX="%{$fg_bold[blue]%}["
 ZSH_THEME_VAGRANT_PROMPT_PREFIX="%{$fg_bold[blue]%}["
@@ -31,3 +35,18 @@ ZSH_THEME_VAGRANT_PROMPT_POWEROFF="%{$fg_no_bold[red]%}●"
 ZSH_THEME_VAGRANT_PROMPT_SUSPENDED="%{$fg_no_bold[yellow]%}●"
 ZSH_THEME_VAGRANT_PROMPT_SUSPENDED="%{$fg_no_bold[yellow]%}●"
 ZSH_THEME_VAGRANT_PROMPT_NOT_CREATED="%{$fg_no_bold[white]%}○"
 ZSH_THEME_VAGRANT_PROMPT_NOT_CREATED="%{$fg_no_bold[white]%}○"
 ```
 ```
+
+### State to variable mapping
+
+The plugin uses the output reported by `vagrant status` to print whichever symbol matches,
+according to the following table:
+
+| State       | Symbol                                 |
+| ----------- | -------------------------------------- |
+| running     | `ZSH_THEME_VAGRANT_PROMPT_RUNNING`     |
+| not running | `ZSH_THEME_VAGRANT_PROMPT_POWEROFF`    |
+| poweroff    | `ZSH_THEME_VAGRANT_PROMPT_POWEROFF`    |
+| paused      | `ZSH_THEME_VAGRANT_PROMPT_SUSPENDED`   |
+| saved       | `ZSH_THEME_VAGRANT_PROMPT_SUSPENDED`   |
+| suspended   | `ZSH_THEME_VAGRANT_PROMPT_SUSPENDED`   |
+| not created | `ZSH_THEME_VAGRANT_PROMPT_NOT_CREATED` |

+ 15 - 13
plugins/vagrant-prompt/vagrant-prompt.plugin.zsh

@@ -1,16 +1,18 @@
 function vagrant_prompt_info() {
 function vagrant_prompt_info() {
-  local vm_states vm_state
-  if [[ -d .vagrant && -f Vagrantfile ]]; then
-    vm_states=(${(f)"$(vagrant status 2> /dev/null | sed -nE 's/^.*(saved|poweroff|running|not created) \([[:alnum:]_]+\)$/\1/p')"})
-    printf '%s' $ZSH_THEME_VAGRANT_PROMPT_PREFIX
-    for vm_state in $vm_states; do
-      case "$vm_state" in
-        saved) printf '%s' $ZSH_THEME_VAGRANT_PROMPT_SUSPENDED ;;
-        running) printf '%s' $ZSH_THEME_VAGRANT_PROMPT_RUNNING ;;
-        poweroff) printf '%s' $ZSH_THEME_VAGRANT_PROMPT_POWEROFF ;;
-        "not created") printf '%s' $ZSH_THEME_VAGRANT_PROMPT_NOT_CREATED ;;
-      esac
-    done
-    printf '%s' $ZSH_THEME_VAGRANT_PROMPT_SUFFIX
+  if [[ ! -d .vagrant || ! -f Vagrantfile ]]; then
+    return
   fi
   fi
+
+  local vm_states vm_state
+  vm_states=(${(f)"$(vagrant status 2> /dev/null | sed -nE 's/^[^ ]* *([[:alnum:] ]*) \([[:alnum:]_]+\)$/\1/p')"})
+  printf '%s' $ZSH_THEME_VAGRANT_PROMPT_PREFIX
+  for vm_state in $vm_states; do
+    case "$vm_state" in
+      running) printf '%s' $ZSH_THEME_VAGRANT_PROMPT_RUNNING ;;
+      "not running"|poweroff) printf '%s' $ZSH_THEME_VAGRANT_PROMPT_POWEROFF ;;
+      paused|saved|suspended) printf '%s' $ZSH_THEME_VAGRANT_PROMPT_SUSPENDED ;;
+      "not created") printf '%s' $ZSH_THEME_VAGRANT_PROMPT_NOT_CREATED ;;
+    esac
+  done
+  printf '%s' $ZSH_THEME_VAGRANT_PROMPT_SUFFIX
 }
 }