fd105b6e528127c2c6f5cf59d0e32d761c206971

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

Refactor and clean up autojump plugin

Diff

 1diff --git a/plugins/autojump/autojump.plugin.zsh b/plugins/autojump/autojump.plugin.zsh
 2index 81664e1ae71ac2b8304781bdd2908e199bfb4c08..7ccd09303348dded3c97028205ee6b83a327d684 100644
 3--- a/plugins/autojump/autojump.plugin.zsh
 4+++ b/plugins/autojump/autojump.plugin.zsh
 5@@ -1,27 +1,34 @@
 6-if [ $commands[autojump] ]; then # check if autojump is installed
 7-  if [ -f $HOME/.autojump/etc/profile.d/autojump.zsh ]; then # manual user-local installation
 8-    source $HOME/.autojump/etc/profile.d/autojump.zsh
 9-  elif [ -f $HOME/.autojump/share/autojump/autojump.zsh ]; then # another manual user-local installation
10-    source $HOME/.autojump/share/autojump/autojump.zsh
11-  elif [ -f $HOME/.nix-profile/etc/profile.d/autojump.sh ]; then # nix installation
12-    source $HOME/.nix-profile/etc/profile.d/autojump.sh
13-  elif [ -f /run/current-system/sw/share/autojump/autojump.zsh ]; then # nixos installation
14-    source /run/current-system/sw/share/autojump/autojump.zsh
15-  elif [ -f /usr/share/autojump/autojump.zsh ]; then # debian and ubuntu package
16-    source /usr/share/autojump/autojump.zsh
17-  elif [ -f /etc/profile.d/autojump.zsh ]; then # manual installation
18-    source /etc/profile.d/autojump.zsh
19-  elif [ -f /etc/profile.d/autojump.sh ]; then # gentoo installation
20-    source /etc/profile.d/autojump.sh
21-  elif [ -f /usr/local/share/autojump/autojump.zsh ]; then # freebsd installation
22-    source /usr/local/share/autojump/autojump.zsh
23-  elif [ -f /opt/local/etc/profile.d/autojump.sh ]; then # mac os x with ports
24-    source /opt/local/etc/profile.d/autojump.sh
25-  elif [ -f /usr/local/etc/profile.d/autojump.sh ]; then # mac os x with brew
26-    source /usr/local/etc/profile.d/autojump.sh
27-  elif [ $commands[brew] -a -f $(brew --prefix)/etc/profile.d/autojump.sh ]; then # mac os x with brew
28-    source $(brew --prefix)/etc/profile.d/autojump.sh
29+(( $+commands[autojump] )) || {
30+  echo '[oh-my-zsh] Please install autojump first (https://github.com/wting/autojump)'
31+  return
32+}
33+
34+declare -a autojump_paths
35+autojump_paths=(
36+  $HOME/.autojump/etc/profile.d/autojump.zsh         # manual installation
37+  $HOME/.autojump/share/autojump/autojump.zsh        # manual installation
38+  $HOME/.nix-profile/etc/profile.d/autojump.sh       # NixOS installation
39+  /run/current-system/sw/share/autojump/autojump.zsh # NixOS installation
40+  /usr/share/autojump/autojump.zsh                   # Debian and Ubuntu package
41+  /etc/profile.d/autojump.zsh                        # manual installation
42+  /etc/profile.d/autojump.sh                         # Gentoo installation
43+  /usr/local/share/autojump/autojump.zsh             # FreeBSD installation
44+  /opt/local/etc/profile.d/autojump.sh               # macOS with MacPorts
45+  /usr/local/etc/profile.d/autojump.sh               # macOS with Homebrew (default)
46+)
47+
48+for file in $autojump_paths; do
49+  if [[ -f "$file" ]]; then
50+    source "$file"
51+    found=1
52+    break
53   fi
54-else
55-  echo 'Please install autojump to enable the plugin (https://github.com/wting/autojump)'
56+done
57+
58+# if no path found, try Homebrew
59+if (( ! found && $+commands[brew] )); then
60+  file=$(brew --prefix)/etc/profile.d/autojump.sh
61+  [[ -f "$file" ]] && source "$file"
62 fi
63+
64+unset autojump_paths file found