Compare View

switch
from
...
to
 
Commits (3)
  • mj
     
  • fd22306 Merge branch 'add-dnf-plugin'
    6245180 Add README to dnf plugin
    c0b1252 Fix deprecated dnf commands
    ee86f1a Create dnf plugin
    26064c6 Merge pull request #4841 from FiloSottile/patch-1
    52737b1 git.plugin: remove the conflicting gvt alias
    a38d7cf Merge pull request #4836 from alias1/patch-1
    2a0be1a Add hash imported from
    db39afe Update _brew to match latest
    15d52fd Merge pull request #4832 from eddie-dunn/master
    78bf3dd pylint.plugin.zsh: Remove include-ids=y
    5464fe3 Center Oh My Zsh logo
    e5f5d79 Merge branch 'low-ghost-patch-1'
    494b07b Update gitignore.plugin: comma separated arguments
    d60cf5c Merge branch 'slariviere-master'
    7daa207 Adding support for stdin input in the encode64 plugin
    40016af Merge pull request #4755 from psprint/master
    77f93f6 znt: optimizations for zsh<=5.2, use $BUFFER if cmd is not from history
    87e782f Merge pull request #4738 from valentinbud/feature-vault
    b9ace28 Vault basic autocompletion.
    071db94 Merge pull request #4713 from apjanke/forklift-new-homepage
    4b9bc91 Merge pull request #4537 from agireud/command-not-found-OSX
    078cd4a Merge pull request #4759 from swrobel/patch-1
    9df79bc Merge pull request #4773 from mbologna/patch-1
    87f8251 Re-added $ZSH_THEME_GIT_PROMPT_EQUAL_REMOTE
    9dd8def forklift: update homepage URL and tweak formatting
    3dfd216 chruby plugin locals moved inside function
    f655793 Add OSX support for command-not-found

    git-subtree-dir: repos/robbyrussell/oh-my-zsh
    git-subtree-split: fd223067c8aea38f09a68746f765ad5aade35e3e

    mj
     
  • mj
     

Changes

Showing 22 changed files Inline Diff

1 zsh-config: 1 zsh-config:
2 =========== 2 ===========
3 3
4 4
5 **Update oh-my-zsh**
6 --------------------
7
8 git fetch --no-tags remote--robbyrussell--oh-my-zsh && \
9 git subtree pull --prefix=repos/robbyrussell/oh-my-zsh remote--robbyrussell--oh-my-zsh master --squash
10
11
12
5 **Update oh-my-zsh** 13 ToDo:
6 -------------------- 14 -----
7 15
8 git fetch --no-tags remote--robbyrussell--oh-my-zsh && \ 16 repos/robbyrussell/oh-my-zsh/plugins/docker-compose/README.md
9 git subtree pull --prefix=repos/robbyrussell/oh-my-zsh remote--robbyrussell--oh-my-zsh master --squash 17
repos/robbyrussell/oh-my-zsh/README.markdown
1 ![Oh My Zsh](https://s3.amazonaws.com/ohmyzsh/oh-my-zsh-logo.png) 1 <p align="center">
2 2 <img src="https://s3.amazonaws.com/ohmyzsh/oh-my-zsh-logo.png" alt="Oh My Zsh">
3 </p>
3 4
4 Oh My Zsh is an open source, community-driven framework for managing your [zsh](http://www.zsh.org/) configuration. That sounds boring. Let's try this again. 5 Oh My Zsh is an open source, community-driven framework for managing your [zsh](http://www.zsh.org/) configuration. That sounds boring. Let's try this again.
5 6
6 __Oh My Zsh is a way of life!__ Once installed, your terminal prompt will become the talk of the town _or your money back!_ Each time you interact with your command prompt, you'll be able to take advantage of the hundreds of bundled plugins and pretty themes. Strangers will come up to you in cafés and ask you, _"that is amazing. are you some sort of genius?"_ Finally, you'll begin to get the sort of attention that you always felt that you deserved. ...or maybe you'll just use the time that you saved to start flossing more often. 7 __Oh My Zsh is a way of life!__ Once installed, your terminal prompt will become the talk of the town _or your money back!_ Each time you interact with your command prompt, you'll be able to take advantage of the hundreds of bundled plugins and pretty themes. Strangers will come up to you in cafés and ask you, _"that is amazing. are you some sort of genius?"_ Finally, you'll begin to get the sort of attention that you always felt that you deserved. ...or maybe you'll just use the time that you saved to start flossing more often.
7 8
8 To learn more, visit [ohmyz.sh](http://ohmyz.sh) and/or follow [ohmyzsh](https://twitter.com/ohmyzsh) on Twitter. 9 To learn more, visit [ohmyz.sh](http://ohmyz.sh) and follow [@ohmyzsh](https://twitter.com/ohmyzsh) on Twitter.
9 10
10 ## Getting Started 11 ## Getting Started
11 12
12
13 ### Prerequisites 13 ### Prerequisites
14 14
15 __Disclaimer:__ _Oh My Zsh works best on Mac OS X and Linux._ 15 __Disclaimer:__ _Oh My Zsh works best on Mac OS X and Linux._
16 16
17 * Unix-based operating system (Mac OS X or Linux) 17 * Unix-based operating system (Mac OS X or Linux)
18 * [Zsh](http://www.zsh.org) should be installed (v4.3.9 or more recent). If not pre-installed (`zsh --version` to confirm), check the following instruction here: [Installing-ZSH](https://github.com/robbyrussell/oh-my-zsh/wiki/Installing-ZSH) 18 * [Zsh](http://www.zsh.org) should be installed (v4.3.9 or more recent). If not pre-installed (`zsh --version` to confirm), check the following instruction here: [Installing ZSH](https://github.com/robbyrussell/oh-my-zsh/wiki/Installing-ZSH)
19 * `curl` or `wget` should be installed 19 * `curl` or `wget` should be installed
20 * `git` should be installed 20 * `git` should be installed
21 21
22 ### Basic Installation 22 ### Basic Installation
23 23
24 Oh My Zsh is installed by running one of the following commands in your terminal. You can install this via the command-line with either `curl` or `wget`. 24 Oh My Zsh is installed by running one of the following commands in your terminal. You can install this via the command-line with either `curl` or `wget`.
25 25
26 #### via curl 26 #### via curl
27 27
28 ```shell 28 ```shell
29 sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" 29 sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
30 ``` 30 ```
31 31
32 #### via wget 32 #### via wget
33 33
34 ```shell 34 ```shell
35 sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)" 35 sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
36 ``` 36 ```
37 37
38 ## Using Oh My Zsh 38 ## Using Oh My Zsh
39 39
40 ### Plugins 40 ### Plugins
41 41
42 Oh My Zsh comes with a shit load of plugins to take advantage of. You can take a look in the [plugins](https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins) directory and/or the [wiki](https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins) to see what's currently available. 42 Oh My Zsh comes with a shit load of plugins to take advantage of. You can take a look in the [plugins](https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins) directory and/or the [wiki](https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins) to see what's currently available.
43 43
44 #### Enabling Plugins 44 #### Enabling Plugins
45 45
46 If you spot a plugin (or several) that you would like to use with Oh My Zsh, you will need to edit the `~/.zshrc` file. Once you open it with your favorite editor, you'll see a spot to list all the plugins that you'd like Oh My Zsh to load in initialization. 46 If you spot a plugin (or several) that you would like to use with Oh My Zsh, you will need to edit the `~/.zshrc` file. Once you open it with your favorite editor, you'll see a spot to list all the plugins that you'd like Oh My Zsh to load in initialization.
47 47
48 For example, this line might begin to look like... 48 For example, this line might begin to look like...
49 49
50 ```shell 50 ```shell
51 plugins=(git bundler osx rake ruby) 51 plugins=(git bundler osx rake ruby)
52 ``` 52 ```
53 53
54 #### Using Plugins 54 #### Using Plugins
55 55
56 Most plugins (should! we're working on this) include a __README__, which documents how to use them. 56 Most plugins (should! we're working on this) include a __README__, which documents how to use them.
57 57
58 ### Themes 58 ### Themes
59 59
60 We'll admit it. Early in the Oh My Zsh world, we may have gotten a bit too theme happy. We have over one hundred themes now bundled. Most of them have [screenshots](https://wiki.github.com/robbyrussell/oh-my-zsh/themes) on the wiki. Check them out! 60 We'll admit it. Early in the Oh My Zsh world, we may have gotten a bit too theme happy. We have over one hundred themes now bundled. Most of them have [screenshots](https://wiki.github.com/robbyrussell/oh-my-zsh/themes) on the wiki. Check them out!
61 61
62 #### Selecting a Theme 62 #### Selecting a Theme
63 63
64 _Robby's theme is the default one. It's not the fanciest one. It's not the simplest one. It's just right (for him)._ 64 _Robby's theme is the default one. It's not the fanciest one. It's not the simplest one. It's just right (for him)._
65 65
66 Once you find a theme that you want to use, you will need to edit the `~/.zshrc` file. You'll see an environment variable (all caps) in there that looks like: 66 Once you find a theme that you want to use, you will need to edit the `~/.zshrc` file. You'll see an environment variable (all caps) in there that looks like:
67 67
68 ```shell 68 ```shell
69 ZSH_THEME="robbyrussell" 69 ZSH_THEME="robbyrussell"
70 ``` 70 ```
71 71
72 To use a different theme, simply change the value to match the name of your desired theme. For example: 72 To use a different theme, simply change the value to match the name of your desired theme. For example:
73 73
74 ```shell 74 ```shell
75 ZSH_THEME="agnoster" # (this is one of the fancy ones) 75 ZSH_THEME="agnoster" # (this is one of the fancy ones)
76 ``` 76 ```
77 77
78 Open up a new terminal window and your prompt should look something like... 78 Open up a new terminal window and your prompt should look something like...
79 79
80 ![Agnoster theme](https://cloud.githubusercontent.com/assets/2618447/6316862/70f58fb6-ba03-11e4-82c9-c083bf9a6574.png) 80 ![Agnoster theme](https://cloud.githubusercontent.com/assets/2618447/6316862/70f58fb6-ba03-11e4-82c9-c083bf9a6574.png)
81 81
82 In case you did not find a suitable theme for your needs, please have a look at the wiki for [more of them](https://github.com/robbyrussell/oh-my-zsh/wiki/External-themes). 82 In case you did not find a suitable theme for your needs, please have a look at the wiki for [more of them](https://github.com/robbyrussell/oh-my-zsh/wiki/External-themes).
83 83
84 If you're feeling feisty, you can let the computer select one randomly for you each time you open a new terminal window. 84 If you're feeling feisty, you can let the computer select one randomly for you each time you open a new terminal window.
85 85
86 86
87 ```shell 87 ```shell
88 ZSH_THEME="random" # (...please let it be pie... please be some pie..) 88 ZSH_THEME="random" # (...please let it be pie... please be some pie..)
89 ``` 89 ```
90 90
91 91
92 ## Advanced Topics 92 ## Advanced Topics
93 93
94 If you're the type that likes to get their hands dirty, these sections might resonate. 94 If you're the type that likes to get their hands dirty, these sections might resonate.
95 95
96 ### Advanced Installation 96 ### Advanced Installation
97 97
98 Some users may want to change the default path, or manually install Oh My Zsh. 98 Some users may want to change the default path, or manually install Oh My Zsh.
99 99
100 #### Custom Directory 100 #### Custom Directory
101 101
102 The default location is `~/.oh-my-zsh` (hidden in your home directory) 102 The default location is `~/.oh-my-zsh` (hidden in your home directory)
103 103
104 If you'd like to change the install directory with the `ZSH` environment variable, either by running `export ZSH=/your/path` before installing, or by setting it before the end of the install pipeline like this: 104 If you'd like to change the install directory with the `ZSH` environment variable, either by running `export ZSH=/your/path` before installing, or by setting it before the end of the install pipeline like this:
105 105
106 ```shell 106 ```shell
107 export ZSH="$HOME/.dotfiles/oh-my-zsh"; sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" 107 export ZSH="$HOME/.dotfiles/oh-my-zsh"; sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
108 ``` 108 ```
109 109
110 #### Manual Installation 110 #### Manual Installation
111 111
112 ##### 1. Clone the repository: 112 ##### 1. Clone the repository:
113 113
114 ```shell 114 ```shell
115 git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh 115 git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
116 ``` 116 ```
117 117
118 ##### 2. *Optionally*, backup your existing `~/.zshrc` file: 118 ##### 2. *Optionally*, backup your existing `~/.zshrc` file:
119 119
120 ```shell 120 ```shell
121 cp ~/.zshrc ~/.zshrc.orig 121 cp ~/.zshrc ~/.zshrc.orig
122 ``` 122 ```
123 123
124 ##### 3. Create a new zsh configuration file 124 ##### 3. Create a new zsh configuration file
125 125
126 You can create a new zsh config file by copying the template that we included for you. 126 You can create a new zsh config file by copying the template that we included for you.
127 127
128 ```shell 128 ```shell
129 cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc 129 cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
130 ``` 130 ```
131 131
132 ##### 4. Change your default shell 132 ##### 4. Change your default shell
133 133
134 ```shell 134 ```shell
135 chsh -s /bin/zsh 135 chsh -s /bin/zsh
136 ``` 136 ```
137 137
138 ##### 5. Initialize your new zsh configuration 138 ##### 5. Initialize your new zsh configuration
139 139
140 Once you open up a new terminal window, it should load zsh with Oh My Zsh's configuration. 140 Once you open up a new terminal window, it should load zsh with Oh My Zsh's configuration.
141 141
142 ### Installation Problems 142 ### Installation Problems
143 143
144 If you have any hiccups installing, here are a few common fixes. 144 If you have any hiccups installing, here are a few common fixes.
145 145
146 * You _might_ need to modify your `PATH` in `~/.zshrc` if you're not able to find some commands after switching to `oh-my-zsh`. 146 * You _might_ need to modify your `PATH` in `~/.zshrc` if you're not able to find some commands after switching to `oh-my-zsh`.
147 * If you installed manually or changed the install location, check the `ZSH` environment variable in `~/.zshrc`. 147 * If you installed manually or changed the install location, check the `ZSH` environment variable in `~/.zshrc`.
148 148
149 ### Custom Plugins and Themes 149 ### Custom Plugins and Themes
150 150
151 If you want to override any of the default behaviors, just add a new file (ending in `.zsh`) in the `custom/` directory. 151 If you want to override any of the default behaviors, just add a new file (ending in `.zsh`) in the `custom/` directory.
152 152
153 If you have many functions that go well together, you can put them as a `XYZ.plugin.zsh` file in the `custom/plugins/` directory and then enable this plugin. 153 If you have many functions that go well together, you can put them as a `XYZ.plugin.zsh` file in the `custom/plugins/` directory and then enable this plugin.
154 154
155 If you would like to override the functionality of a plugin distributed with Oh My Zsh, create a plugin of the same name in the `custom/plugins/` directory and it will be loaded instead of the one in `plugins/`. 155 If you would like to override the functionality of a plugin distributed with Oh My Zsh, create a plugin of the same name in the `custom/plugins/` directory and it will be loaded instead of the one in `plugins/`.
156 156
157 ## Getting Updates 157 ## Getting Updates
158 158
159 By default, you will be prompted to check for upgrades every few weeks. If you would like `oh-my-zsh` to automatically upgrade itself without prompting you, set the following in your `~/.zshrc`: 159 By default, you will be prompted to check for upgrades every few weeks. If you would like `oh-my-zsh` to automatically upgrade itself without prompting you, set the following in your `~/.zshrc`:
160 160
161 ```shell 161 ```shell
162 DISABLE_UPDATE_PROMPT=true 162 DISABLE_UPDATE_PROMPT=true
163 ``` 163 ```
164 164
165 To disable automatic upgrades, set the following in your `~/.zshrc`: 165 To disable automatic upgrades, set the following in your `~/.zshrc`:
166 166
167 ```shell 167 ```shell
168 DISABLE_AUTO_UPDATE=true 168 DISABLE_AUTO_UPDATE=true
169 ``` 169 ```
170 170
171 ### Manual Updates 171 ### Manual Updates
172 172
173 If you'd like to upgrade at any point in time (maybe someone just released a new plugin and you don't want to wait a week?) you just need to run: 173 If you'd like to upgrade at any point in time (maybe someone just released a new plugin and you don't want to wait a week?) you just need to run:
174 174
175 ```shell 175 ```shell
176 upgrade_oh_my_zsh 176 upgrade_oh_my_zsh
177 ``` 177 ```
178 178
179 Magic! 179 Magic!
180 180
181 ## Uninstalling Oh My Zsh 181 ## Uninstalling Oh My Zsh
182 182
183 Oh My Zsh isn't for everyone. We'll miss you, but we want to make this an easy breakup. 183 Oh My Zsh isn't for everyone. We'll miss you, but we want to make this an easy breakup.
184 184
185 If you want to uninstall `oh-my-zsh`, just run `uninstall_oh_my_zsh` from the command-line. It will remove itself and revert your previous `bash` or `zsh` configuration. 185 If you want to uninstall `oh-my-zsh`, just run `uninstall_oh_my_zsh` from the command-line. It will remove itself and revert your previous `bash` or `zsh` configuration.
186 186
187 ## Contributing 187 ## Contributing
188 188
189 I'm far from being a [Zsh](http://www.zsh.org/) expert and suspect there are many ways to improve – if you have ideas on how to make the configuration easier to maintain (and faster), don't hesitate to fork and send pull requests! 189 I'm far from being a [Zsh](http://www.zsh.org/) expert and suspect there are many ways to improve – if you have ideas on how to make the configuration easier to maintain (and faster), don't hesitate to fork and send pull requests!
190 190
191 We also need people to test out pull-requests. So take a look through [the open issues](https://github.com/robbyrussell/oh-my-zsh/issues) and help where you can. 191 We also need people to test out pull-requests. So take a look through [the open issues](https://github.com/robbyrussell/oh-my-zsh/issues) and help where you can.
192 192
193 ### Do NOT send us themes 193 ### Do NOT send us themes
194 194
195 We have (more than) enough themes for the time being. Please add your theme to the [external themes](https://github.com/robbyrussell/oh-my-zsh/wiki/External-themes) wiki page. 195 We have (more than) enough themes for the time being. Please add your theme to the [external themes](https://github.com/robbyrussell/oh-my-zsh/wiki/External-themes) wiki page.
196 196
197 ## Contributors 197 ## Contributors
198 198
199 Oh My Zsh has a vibrant community of happy users and delightful contributors. Without all the time and help from our contributors, it wouldn't be so awesome. 199 Oh My Zsh has a vibrant community of happy users and delightful contributors. Without all the time and help from our contributors, it wouldn't be so awesome.
200 200
201 Thank you so much! 201 Thank you so much!
202 202
203 ## Follow Us 203 ## Follow Us
204 204
205 We have an [@ohmyzsh](https://twitter.com/ohmyzsh) Twitter account. You should follow it. 205 We have an [@ohmyzsh](https://twitter.com/ohmyzsh) Twitter account. You should follow it.
206 206
207 ## Merchandise 207 ## Merchandise
208 208
209 We have [stickers](http://shop.planetargon.com/products/ohmyzsh-stickers-set-of-3-stickers) and [shirts](http://shop.planetargon.com/products/ohmyzsh-t-shirts) for you to show off your love of Oh My Zsh. Again, this will help you become the talk of the town! 209 We have [stickers](http://shop.planetargon.com/products/ohmyzsh-stickers-set-of-3-stickers) and [shirts](http://shop.planetargon.com/products/ohmyzsh-t-shirts) for you to show off your love of Oh My Zsh. Again, this will help you become the talk of the town!
210 210
211 ## License 211 ## License
212 212
213 Oh My Zsh is released under the [MIT license](MIT-LICENSE.txt). 213 Oh My Zsh is released under the [MIT license](MIT-LICENSE.txt).
repos/robbyrussell/oh-my-zsh/lib/git.zsh
1 # Outputs current branch info in prompt format 1 # Outputs current branch info in prompt format
2 function git_prompt_info() { 2 function git_prompt_info() {
3 local ref 3 local ref
4 if [[ "$(command git config --get oh-my-zsh.hide-status 2>/dev/null)" != "1" ]]; then 4 if [[ "$(command git config --get oh-my-zsh.hide-status 2>/dev/null)" != "1" ]]; then
5 ref=$(command git symbolic-ref HEAD 2> /dev/null) || \ 5 ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
6 ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0 6 ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0
7 echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX" 7 echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
8 fi 8 fi
9 } 9 }
10 10
11 # Checks if working tree is dirty 11 # Checks if working tree is dirty
12 function parse_git_dirty() { 12 function parse_git_dirty() {
13 local STATUS='' 13 local STATUS=''
14 local FLAGS 14 local FLAGS
15 FLAGS=('--porcelain') 15 FLAGS=('--porcelain')
16 if [[ "$(command git config --get oh-my-zsh.hide-dirty)" != "1" ]]; then 16 if [[ "$(command git config --get oh-my-zsh.hide-dirty)" != "1" ]]; then
17 if [[ $POST_1_7_2_GIT -gt 0 ]]; then 17 if [[ $POST_1_7_2_GIT -gt 0 ]]; then
18 FLAGS+='--ignore-submodules=dirty' 18 FLAGS+='--ignore-submodules=dirty'
19 fi 19 fi
20 if [[ "$DISABLE_UNTRACKED_FILES_DIRTY" == "true" ]]; then 20 if [[ "$DISABLE_UNTRACKED_FILES_DIRTY" == "true" ]]; then
21 FLAGS+='--untracked-files=no' 21 FLAGS+='--untracked-files=no'
22 fi 22 fi
23 STATUS=$(command git status ${FLAGS} 2> /dev/null | tail -n1) 23 STATUS=$(command git status ${FLAGS} 2> /dev/null | tail -n1)
24 fi 24 fi
25 if [[ -n $STATUS ]]; then 25 if [[ -n $STATUS ]]; then
26 echo "$ZSH_THEME_GIT_PROMPT_DIRTY" 26 echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
27 else 27 else
28 echo "$ZSH_THEME_GIT_PROMPT_CLEAN" 28 echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
29 fi 29 fi
30 } 30 }
31 31
32 # Gets the difference between the local and remote branches 32 # Gets the difference between the local and remote branches
33 function git_remote_status() { 33 function git_remote_status() {
34 local remote ahead behind git_remote_status git_remote_status_detailed 34 local remote ahead behind git_remote_status git_remote_status_detailed
35 remote=${$(command git rev-parse --verify ${hook_com[branch]}@{upstream} --symbolic-full-name 2>/dev/null)/refs\/remotes\/} 35 remote=${$(command git rev-parse --verify ${hook_com[branch]}@{upstream} --symbolic-full-name 2>/dev/null)/refs\/remotes\/}
36 if [[ -n ${remote} ]]; then 36 if [[ -n ${remote} ]]; then
37 ahead=$(command git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l) 37 ahead=$(command git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l)
38 behind=$(command git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l) 38 behind=$(command git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l)
39 39
40 if [[ $ahead -gt 0 ]] && [[ $behind -eq 0 ]]; then 40 if [[ $ahead -eq 0 ]] && [[ $behind -eq 0 ]]; then
41 git_remote_status="$ZSH_THEME_GIT_PROMPT_EQUAL_REMOTE"
42 elif [[ $ahead -gt 0 ]] && [[ $behind -eq 0 ]]; then
41 git_remote_status="$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE" 43 git_remote_status="$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE"
42 git_remote_status_detailed="$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE_COLOR$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE$((ahead))%{$reset_color%}" 44 git_remote_status_detailed="$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE_COLOR$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE$((ahead))%{$reset_color%}"
43 elif [[ $behind -gt 0 ]] && [[ $ahead -eq 0 ]]; then 45 elif [[ $behind -gt 0 ]] && [[ $ahead -eq 0 ]]; then
44 git_remote_status="$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE" 46 git_remote_status="$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE"
45 git_remote_status_detailed="$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE_COLOR$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE$((behind))%{$reset_color%}" 47 git_remote_status_detailed="$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE_COLOR$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE$((behind))%{$reset_color%}"
46 elif [[ $ahead -gt 0 ]] && [[ $behind -gt 0 ]]; then 48 elif [[ $ahead -gt 0 ]] && [[ $behind -gt 0 ]]; then
47 git_remote_status="$ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE" 49 git_remote_status="$ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE"
48 git_remote_status_detailed="$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE_COLOR$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE$((ahead))%{$reset_color%}$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE_COLOR$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE$((behind))%{$reset_color%}" 50 git_remote_status_detailed="$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE_COLOR$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE$((ahead))%{$reset_color%}$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE_COLOR$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE$((behind))%{$reset_color%}"
49 fi 51 fi
50 52
51 if [[ -n $ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_DETAILED ]]; then 53 if [[ -n $ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_DETAILED ]]; then
52 git_remote_status="$ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_PREFIX$remote$git_remote_status_detailed$ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_SUFFIX" 54 git_remote_status="$ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_PREFIX$remote$git_remote_status_detailed$ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_SUFFIX"
53 fi 55 fi
54 56
55 echo $git_remote_status 57 echo $git_remote_status
56 fi 58 fi
57 } 59 }
58 60
59 # Outputs the name of the current branch 61 # Outputs the name of the current branch
60 # Usage example: git pull origin $(git_current_branch) 62 # Usage example: git pull origin $(git_current_branch)
61 # Using '--quiet' with 'symbolic-ref' will not cause a fatal error (128) if 63 # Using '--quiet' with 'symbolic-ref' will not cause a fatal error (128) if
62 # it's not a symbolic ref, but in a Git repo. 64 # it's not a symbolic ref, but in a Git repo.
63 function git_current_branch() { 65 function git_current_branch() {
64 local ref 66 local ref
65 ref=$(command git symbolic-ref --quiet HEAD 2> /dev/null) 67 ref=$(command git symbolic-ref --quiet HEAD 2> /dev/null)
66 local ret=$? 68 local ret=$?
67 if [[ $ret != 0 ]]; then 69 if [[ $ret != 0 ]]; then
68 [[ $ret == 128 ]] && return # no git repo. 70 [[ $ret == 128 ]] && return # no git repo.
69 ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 71 ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
70 fi 72 fi
71 echo ${ref#refs/heads/} 73 echo ${ref#refs/heads/}
72 } 74 }
73 75
74 76
75 # Gets the number of commits ahead from remote 77 # Gets the number of commits ahead from remote
76 function git_commits_ahead() { 78 function git_commits_ahead() {
77 if $(echo "$(command git log @{upstream}..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then 79 if $(echo "$(command git log @{upstream}..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then
78 local COMMITS 80 local COMMITS
79 COMMITS=$(command git log @{upstream}..HEAD | grep '^commit' | wc -l | tr -d ' ') 81 COMMITS=$(command git log @{upstream}..HEAD | grep '^commit' | wc -l | tr -d ' ')
80 echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$COMMITS$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX" 82 echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$COMMITS$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX"
81 fi 83 fi
82 } 84 }
83 85
84 # Outputs if current branch is ahead of remote 86 # Outputs if current branch is ahead of remote
85 function git_prompt_ahead() { 87 function git_prompt_ahead() {
86 if [[ -n "$(command git rev-list origin/$(git_current_branch)..HEAD 2> /dev/null)" ]]; then 88 if [[ -n "$(command git rev-list origin/$(git_current_branch)..HEAD 2> /dev/null)" ]]; then
87 echo "$ZSH_THEME_GIT_PROMPT_AHEAD" 89 echo "$ZSH_THEME_GIT_PROMPT_AHEAD"
88 fi 90 fi
89 } 91 }
90 92
91 # Outputs if current branch is behind remote 93 # Outputs if current branch is behind remote
92 function git_prompt_behind() { 94 function git_prompt_behind() {
93 if [[ -n "$(command git rev-list HEAD..origin/$(git_current_branch) 2> /dev/null)" ]]; then 95 if [[ -n "$(command git rev-list HEAD..origin/$(git_current_branch) 2> /dev/null)" ]]; then
94 echo "$ZSH_THEME_GIT_PROMPT_BEHIND" 96 echo "$ZSH_THEME_GIT_PROMPT_BEHIND"
95 fi 97 fi
96 } 98 }
97 99
98 # Outputs if current branch exists on remote or not 100 # Outputs if current branch exists on remote or not
99 function git_prompt_remote() { 101 function git_prompt_remote() {
100 if [[ -n "$(command git show-ref origin/$(git_current_branch) 2> /dev/null)" ]]; then 102 if [[ -n "$(command git show-ref origin/$(git_current_branch) 2> /dev/null)" ]]; then
101 echo "$ZSH_THEME_GIT_PROMPT_REMOTE_EXISTS" 103 echo "$ZSH_THEME_GIT_PROMPT_REMOTE_EXISTS"
102 else 104 else
103 echo "$ZSH_THEME_GIT_PROMPT_REMOTE_MISSING" 105 echo "$ZSH_THEME_GIT_PROMPT_REMOTE_MISSING"
104 fi 106 fi
105 } 107 }
106 108
107 # Formats prompt string for current git commit short SHA 109 # Formats prompt string for current git commit short SHA
108 function git_prompt_short_sha() { 110 function git_prompt_short_sha() {
109 local SHA 111 local SHA
110 SHA=$(command git rev-parse --short HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER" 112 SHA=$(command git rev-parse --short HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
111 } 113 }
112 114
113 # Formats prompt string for current git commit long SHA 115 # Formats prompt string for current git commit long SHA
114 function git_prompt_long_sha() { 116 function git_prompt_long_sha() {
115 local SHA 117 local SHA
116 SHA=$(command git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER" 118 SHA=$(command git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
117 } 119 }
118 120
119 # Get the status of the working tree 121 # Get the status of the working tree
120 function git_prompt_status() { 122 function git_prompt_status() {
121 local INDEX STATUS 123 local INDEX STATUS
122 INDEX=$(command git status --porcelain -b 2> /dev/null) 124 INDEX=$(command git status --porcelain -b 2> /dev/null)
123 STATUS="" 125 STATUS=""
124 if $(echo "$INDEX" | command grep -E '^\?\? ' &> /dev/null); then 126 if $(echo "$INDEX" | command grep -E '^\?\? ' &> /dev/null); then
125 STATUS="$ZSH_THEME_GIT_PROMPT_UNTRACKED$STATUS" 127 STATUS="$ZSH_THEME_GIT_PROMPT_UNTRACKED$STATUS"
126 fi 128 fi
127 if $(echo "$INDEX" | grep '^A ' &> /dev/null); then 129 if $(echo "$INDEX" | grep '^A ' &> /dev/null); then
128 STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS" 130 STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS"
129 elif $(echo "$INDEX" | grep '^M ' &> /dev/null); then 131 elif $(echo "$INDEX" | grep '^M ' &> /dev/null); then
130 STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS" 132 STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS"
131 fi 133 fi
132 if $(echo "$INDEX" | grep '^ M ' &> /dev/null); then 134 if $(echo "$INDEX" | grep '^ M ' &> /dev/null); then
133 STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS" 135 STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
134 elif $(echo "$INDEX" | grep '^AM ' &> /dev/null); then 136 elif $(echo "$INDEX" | grep '^AM ' &> /dev/null); then
135 STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS" 137 STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
136 elif $(echo "$INDEX" | grep '^ T ' &> /dev/null); then 138 elif $(echo "$INDEX" | grep '^ T ' &> /dev/null); then
137 STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS" 139 STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
138 fi 140 fi
139 if $(echo "$INDEX" | grep '^R ' &> /dev/null); then 141 if $(echo "$INDEX" | grep '^R ' &> /dev/null); then
140 STATUS="$ZSH_THEME_GIT_PROMPT_RENAMED$STATUS" 142 STATUS="$ZSH_THEME_GIT_PROMPT_RENAMED$STATUS"
141 fi 143 fi
142 if $(echo "$INDEX" | grep '^ D ' &> /dev/null); then 144 if $(echo "$INDEX" | grep '^ D ' &> /dev/null); then
143 STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS" 145 STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
144 elif $(echo "$INDEX" | grep '^D ' &> /dev/null); then 146 elif $(echo "$INDEX" | grep '^D ' &> /dev/null); then
145 STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS" 147 STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
146 elif $(echo "$INDEX" | grep '^AD ' &> /dev/null); then 148 elif $(echo "$INDEX" | grep '^AD ' &> /dev/null); then
147 STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS" 149 STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
148 fi 150 fi
149 if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then 151 if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then
150 STATUS="$ZSH_THEME_GIT_PROMPT_STASHED$STATUS" 152 STATUS="$ZSH_THEME_GIT_PROMPT_STASHED$STATUS"
151 fi 153 fi
152 if $(echo "$INDEX" | grep '^UU ' &> /dev/null); then 154 if $(echo "$INDEX" | grep '^UU ' &> /dev/null); then
153 STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS" 155 STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS"
154 fi 156 fi
155 if $(echo "$INDEX" | grep '^## .*ahead' &> /dev/null); then 157 if $(echo "$INDEX" | grep '^## .*ahead' &> /dev/null); then
156 STATUS="$ZSH_THEME_GIT_PROMPT_AHEAD$STATUS" 158 STATUS="$ZSH_THEME_GIT_PROMPT_AHEAD$STATUS"
157 fi 159 fi
158 if $(echo "$INDEX" | grep '^## .*behind' &> /dev/null); then 160 if $(echo "$INDEX" | grep '^## .*behind' &> /dev/null); then
159 STATUS="$ZSH_THEME_GIT_PROMPT_BEHIND$STATUS" 161 STATUS="$ZSH_THEME_GIT_PROMPT_BEHIND$STATUS"
160 fi 162 fi
161 if $(echo "$INDEX" | grep '^## .*diverged' &> /dev/null); then 163 if $(echo "$INDEX" | grep '^## .*diverged' &> /dev/null); then
162 STATUS="$ZSH_THEME_GIT_PROMPT_DIVERGED$STATUS" 164 STATUS="$ZSH_THEME_GIT_PROMPT_DIVERGED$STATUS"
163 fi 165 fi
164 echo $STATUS 166 echo $STATUS
165 } 167 }
166 168
167 # Compares the provided version of git to the version installed and on path 169 # Compares the provided version of git to the version installed and on path
168 # Outputs -1, 0, or 1 if the installed version is less than, equal to, or 170 # Outputs -1, 0, or 1 if the installed version is less than, equal to, or
169 # greater than the input version, respectively. 171 # greater than the input version, respectively.
170 function git_compare_version() { 172 function git_compare_version() {
171 local INPUT_GIT_VERSION INSTALLED_GIT_VERSION 173 local INPUT_GIT_VERSION INSTALLED_GIT_VERSION
172 INPUT_GIT_VERSION=(${(s/./)1}) 174 INPUT_GIT_VERSION=(${(s/./)1})
173 INSTALLED_GIT_VERSION=($(command git --version 2>/dev/null)) 175 INSTALLED_GIT_VERSION=($(command git --version 2>/dev/null))
174 INSTALLED_GIT_VERSION=(${(s/./)INSTALLED_GIT_VERSION[3]}) 176 INSTALLED_GIT_VERSION=(${(s/./)INSTALLED_GIT_VERSION[3]})
175 177
176 for i in {1..3}; do 178 for i in {1..3}; do
177 if [[ $INSTALLED_GIT_VERSION[$i] -gt $INPUT_GIT_VERSION[$i] ]]; then 179 if [[ $INSTALLED_GIT_VERSION[$i] -gt $INPUT_GIT_VERSION[$i] ]]; then
178 echo 1 180 echo 1
179 return 0 181 return 0
180 fi 182 fi
181 if [[ $INSTALLED_GIT_VERSION[$i] -lt $INPUT_GIT_VERSION[$i] ]]; then 183 if [[ $INSTALLED_GIT_VERSION[$i] -lt $INPUT_GIT_VERSION[$i] ]]; then
182 echo -1 184 echo -1
183 return 0 185 return 0
184 fi 186 fi
185 done 187 done
186 echo 0 188 echo 0
187 } 189 }
188 190
189 # This is unlikely to change so make it all statically assigned 191 # This is unlikely to change so make it all statically assigned
190 POST_1_7_2_GIT=$(git_compare_version "1.7.2") 192 POST_1_7_2_GIT=$(git_compare_version "1.7.2")
191 # Clean up the namespace slightly by removing the checker function 193 # Clean up the namespace slightly by removing the checker function
192 unfunction git_compare_version 194 unfunction git_compare_version
193 195
repos/robbyrussell/oh-my-zsh/plugins/brew/_brew
1 #compdef brew 1 #compdef brew
2 #autoload 2 #autoload
3 3
4 # imported from the latest homebrew contributions 4 # imported from https://github.com/Homebrew/homebrew/blob/29f73d2212c2b202fe25f69dcbf440d8391fa4c9/Library/Contributions/brew_zsh_completion.zsh
5
6 # Brew ZSH completion function
7 # Drop this somewhere in your $fpath (like /usr/share/zsh/site-functions)
8 # and rename it _brew
9 #
10 # altered from _fink
5 11
6 _brew_all_formulae() { 12 _brew_all_formulae() {
7 formulae=(`brew search`) 13 formulae=(`brew search`)
8 } 14 }
9 15
10 _brew_installed_formulae() { 16 _brew_installed_formulae() {
11 installed_formulae=(`brew list`) 17 installed_formulae=(`brew list`)
12 } 18 }
13 19
14 _brew_installed_taps() { 20 _brew_installed_taps() {
15 installed_taps=(`brew tap`) 21 installed_taps=(`brew tap`)
16 } 22 }
17 23
24 _brew_official_taps() {
25 official_taps=(`brew tap --list-official`)
26 }
27
28 _brew_pinned_taps() {
29 pinned_taps=(`brew tap --list-pinned`)
30 }
31
18 _brew_outdated_formulae() { 32 _brew_outdated_formulae() {
19 outdated_formulae=(`brew outdated`) 33 outdated_formulae=(`brew outdated`)
20 } 34 }
21 35
22 local -a _1st_arguments 36 local -a _1st_arguments
23 _1st_arguments=( 37 _1st_arguments=(
24 'audit:check formulae for Homebrew coding style' 38 'audit:check formulae for Homebrew coding style'
25 'cat:display formula file for a formula' 39 'cat:display formula file for a formula'
26 'cleanup:uninstall unused and old versions of packages' 40 'cleanup:uninstall unused and old versions of packages'
27 'commands:show a list of commands' 41 'commands:show a list of commands'
42 'config:show homebrew and system configuration'
28 'create:create a new formula' 43 'create:create a new formula'
29 'deps:list dependencies of a formula' 44 'deps:list dependencies and dependants of a formula'
45 'desc:display a description of a formula'
30 'doctor:audits your installation for common issues' 46 'doctor:audits your installation for common issues'
31 'edit:edit a formula' 47 'edit:edit a formula'
32 'fetch:download formula resources to the cache' 48 'fetch:download formula resources to the cache'
33 'gist-logs:generate a gist of the full build logs' 49 'gist-logs:generate a gist of the full build logs'
34 'home:visit the homepage of a formula or the brew project' 50 'home:visit the homepage of a formula or the brew project'
35 'info:information about a formula' 51 'info:information about a formula'
36 'install:install a formula' 52 'install:install a formula'
37 'reinstall:install a formula anew; re-using its current options' 53 'reinstall:install a formula anew; re-using its current options'
38 'leaves:show installed formulae that are not dependencies of another installed formula' 54 'leaves:show installed formulae that are not dependencies of another installed formula'
39 'link:link a formula' 55 'link:link a formula'
56 'linkapps:symlink .app bundles provided by formulae into /Applications'
40 'list:list files in a formula or not-installed formulae' 57 'list:list files in a formula or not-installed formulae'
41 'log:git commit log for a formula' 58 'log:git commit log for a formula'
42 'missing:check all installed formuale for missing dependencies.' 59 'missing:check all installed formuale for missing dependencies.'
60 'migrate:migrate renamed formula to new name'
43 'outdated:list formulae for which a newer version is available' 61 'outdated:list formulae for which a newer version is available'
44 'pin:pin specified formulae' 62 'pin:pin specified formulae'
45 'postinstall:perform post_install for a given formula' 63 'postinstall:perform post_install for a given formula'
46 'prune:remove dead links' 64 'prune:remove dead links'
47 'remove:remove a formula' 65 'remove:remove a formula'
48 'search:search for a formula (/regex/ or string)' 66 'search:search for a formula (/regex/ or string)'
49 'switch:switch linkage between installed versions of a formula' 67 'switch:switch between different versions of a formula'
50 'tap:tap a new formula repository from GitHub, or list existing taps' 68 'tap:tap a new formula repository from GitHub, or list existing taps'
69 'tap-info:information about a tap'
70 'tap-pin:pin a tap'
71 'tap-unpin:unpin a tap'
51 'test-bot:test a formula and build a bottle' 72 'test-bot:test a formula and build a bottle'
52 'uninstall:uninstall a formula' 73 'uninstall:uninstall a formula'
53 'unlink:unlink a formula' 74 'unlink:unlink a formula'
75 'unlinkapps:remove symlinked .app bundles provided by formulae from /Applications'
54 'unpin:unpin specified formulae' 76 'unpin:unpin specified formulae'
55 'untap:remove a tapped repository' 77 'untap:remove a tapped repository'
56 'update:pull latest repository' 78 'update:fetch latest version of Homebrew and all formulae'
57 'upgrade:upgrade outdated formulae' 79 'upgrade:upgrade outdated formulae'
58 'uses:show formulae which depend on a formula' 80 'uses:show formulae which depend on a formula'
81 `brew commands --quiet --include-aliases`
59 ) 82 )
60 83
61 local expl 84 local expl
62 local -a formulae installed_formulae installed_taps outdated_formulae 85 local -a formulae installed_formulae installed_taps official_taps outdated_formulae
63 86
64 _arguments \ 87 _arguments \
65 '(-v)-v[verbose]' \ 88 '(-v)-v[verbose]' \
66 '(--cellar)--cellar[brew cellar]' \ 89 '(--cellar)--cellar[brew cellar]' \
67 '(--config)--config[brew configuration]' \
68 '(--env)--env[brew environment]' \ 90 '(--env)--env[brew environment]' \
69 '(--repository)--repository[brew repository]' \ 91 '(--repository)--repository[brew repository]' \
70 '(--version)--version[version information]' \ 92 '(--version)--version[version information]' \
71 '(--prefix)--prefix[where brew lives on this system]' \ 93 '(--prefix)--prefix[where brew lives on this system]' \
72 '(--cache)--cache[brew cache]' \ 94 '(--cache)--cache[brew cache]' \
73 '(--force)--force[brew force]' \
74 '*:: :->subcmds' && return 0 95 '*:: :->subcmds' && return 0
75 96
76 if (( CURRENT == 1 )); then 97 if (( CURRENT == 1 )); then
77 _describe -t commands "brew subcommand" _1st_arguments 98 _describe -t commands "brew subcommand" _1st_arguments
78 return 99 return
79 fi 100 fi
80 101
81 case "$words[1]" in 102 case "$words[1]" in
82 install|reinstall|audit|home|homepage|log|info|abv|uses|cat|deps|edit|options) 103 install|reinstall|audit|home|homepage|log|info|abv|uses|cat|deps|desc|edit|options|switch)
83 _brew_all_formulae 104 _brew_all_formulae
84 _wanted formulae expl 'all formulae' compadd -a formulae ;; 105 _wanted formulae expl 'all formulae' compadd -a formulae ;;
106 linkapps|unlinkapps)
107 _arguments \
108 '(--local)--local[operate on ~/Applications instead of /Applications]' \
109 '1: :->forms' && return 0
110
111 if [[ "$state" == forms ]]; then
112 _brew_installed_formulae
113 _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae
114 fi ;;
85 list|ls) 115 list|ls)
86 _arguments \ 116 _arguments \
87 '(--unbrewed)--unbrewed[files in brew --prefix not controlled by brew]' \ 117 '(--unbrewed)--unbrewed[files in brew --prefix not controlled by brew]' \
88 '(--pinned)--pinned[list all versions of pinned formulae]' \ 118 '(--pinned)--pinned[list all versions of pinned formulae]' \
89 '(--versions)--versions[list all installed versions of a formula]' \ 119 '(--versions)--versions[list all installed versions of a formula]' \
90 '1: :->forms' && return 0 120 '1: :->forms' && return 0
91 121
92 if [[ "$state" == forms ]]; then 122 if [[ "$state" == forms ]]; then
93 _brew_installed_formulae 123 _brew_installed_formulae
94 _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae 124 _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae
95 fi ;; 125 fi ;;
96 remove|rm|uninstall|unlink|cleanup|link|ln|pin|unpin) 126 remove|rm|uninstall|unlink|cleanup|link|ln|pin|unpin)
97 _brew_installed_formulae 127 _brew_installed_formulae
98 _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae ;; 128 _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae ;;
99 search|-S) 129 search|-S)
100 _arguments \ 130 _arguments \
101 '(--macports)--macports[search the macports repository]' \ 131 '(--macports)--macports[search the macports repository]' \
102 '(--fink)--fink[search the fink repository]' ;; 132 '(--fink)--fink[search the fink repository]' ;;
103 untap) 133 untap|tap-info|tap-pin)
104 _brew_installed_taps 134 _brew_installed_taps
105 _wanted installed_taps expl 'installed taps' compadd -a installed_taps ;; 135 _wanted installed_taps expl 'installed taps' compadd -a installed_taps ;;
136 tap)
137 _brew_official_taps
138 _wanted official_taps expl 'official taps' compadd -a official_taps ;;
139 tap-unpin)
140 _brew_pinned_taps
141 _wanted pinned_taps expl 'pinned taps' compadd -a pinned_taps ;;
106 upgrade) 142 upgrade)
107 _brew_outdated_formulae 143 _brew_outdated_formulae
108 _wanted outdated_formulae expl 'outdated formulae' compadd -a outdated_formulae ;; 144 _wanted outdated_formulae expl 'outdated formulae' compadd -a outdated_formulae ;;
repos/robbyrussell/oh-my-zsh/plugins/chruby/chruby.plugin.zsh
1 # 1 #
2 # INSTRUCTIONS 2 # INSTRUCTIONS
3 # 3 #
4 # With either a manual or brew installed chruby things should just work. 4 # With either a manual or brew installed chruby things should just work.
5 # 5 #
6 # If you'd prefer to specify an explicit path to load chruby from 6 # If you'd prefer to specify an explicit path to load chruby from
7 # you can set variables like so: 7 # you can set variables like so:
8 # 8 #
9 # zstyle :omz:plugins:chruby path /local/path/to/chruby.sh 9 # zstyle :omz:plugins:chruby path /local/path/to/chruby.sh
10 # zstyle :omz:plugins:chruby auto /local/path/to/auto.sh 10 # zstyle :omz:plugins:chruby auto /local/path/to/auto.sh
11 # 11 #
12 # TODO 12 # TODO
13 # - autodetermine correct source path on non OS X systems 13 # - autodetermine correct source path on non OS X systems
14 # - completion if ruby-install exists 14 # - completion if ruby-install exists
15 15
16 # rvm and rbenv plugins also provide this alias 16 # rvm and rbenv plugins also provide this alias
17 alias rubies='chruby' 17 alias rubies='chruby'
18 18
19 local _chruby_path
20 local _chruby_auto
21
22 _homebrew-installed() { 19 _homebrew-installed() {
23 whence brew &> /dev/null 20 whence brew &> /dev/null
24 } 21 }
25 22
26 _chruby-from-homebrew-installed() { 23 _chruby-from-homebrew-installed() {
27 [ -r $(brew --prefix chruby) ] &> /dev/null 24 [ -r $(brew --prefix chruby) ] &> /dev/null
28 } 25 }
29 26
30 _ruby-build_installed() { 27 _ruby-build_installed() {
31 whence ruby-build &> /dev/null 28 whence ruby-build &> /dev/null
32 } 29 }
33 30
34 _ruby-install-installed() { 31 _ruby-install-installed() {
35 whence ruby-install &> /dev/null 32 whence ruby-install &> /dev/null
36 } 33 }
37 34
38 # Simple definition completer for ruby-build 35 # Simple definition completer for ruby-build
39 if _ruby-build_installed; then 36 if _ruby-build_installed; then
40 _ruby-build() { compadd $(ruby-build --definitions) } 37 _ruby-build() { compadd $(ruby-build --definitions) }
41 compdef _ruby-build ruby-build 38 compdef _ruby-build ruby-build
42 fi 39 fi
43 40
44 _source_from_omz_settings() { 41 _source_from_omz_settings() {
42 local _chruby_path
43 local _chruby_auto
44
45 zstyle -s :omz:plugins:chruby path _chruby_path 45 zstyle -s :omz:plugins:chruby path _chruby_path
46 zstyle -s :omz:plugins:chruby auto _chruby_auto 46 zstyle -s :omz:plugins:chruby auto _chruby_auto
47 47
48 if [[ -r ${_chruby_path} ]]; then 48 if [[ -r ${_chruby_path} ]]; then
49 source ${_chruby_path} 49 source ${_chruby_path}
50 fi 50 fi
51 51
52 if [[ -r ${_chruby_auto} ]]; then 52 if [[ -r ${_chruby_auto} ]]; then
53 source ${_chruby_auto} 53 source ${_chruby_auto}
54 fi 54 fi
55 } 55 }
56 56
57 _chruby_dirs() { 57 _chruby_dirs() {
58 chrubydirs=($HOME/.rubies/ $PREFIX/opt/rubies) 58 chrubydirs=($HOME/.rubies/ $PREFIX/opt/rubies)
59 for dir in chrubydirs; do 59 for dir in chrubydirs; do
60 if [[ -d $dir ]]; then 60 if [[ -d $dir ]]; then
61 RUBIES+=$dir 61 RUBIES+=$dir
62 fi 62 fi
63 done 63 done
64 } 64 }
65 65
66 if _homebrew-installed && _chruby-from-homebrew-installed ; then 66 if _homebrew-installed && _chruby-from-homebrew-installed ; then
67 source $(brew --prefix chruby)/share/chruby/chruby.sh 67 source $(brew --prefix chruby)/share/chruby/chruby.sh
68 source $(brew --prefix chruby)/share/chruby/auto.sh 68 source $(brew --prefix chruby)/share/chruby/auto.sh
69 _chruby_dirs 69 _chruby_dirs
70 elif [[ -r "/usr/local/share/chruby/chruby.sh" ]] ; then 70 elif [[ -r "/usr/local/share/chruby/chruby.sh" ]] ; then
71 source /usr/local/share/chruby/chruby.sh 71 source /usr/local/share/chruby/chruby.sh
72 source /usr/local/share/chruby/auto.sh 72 source /usr/local/share/chruby/auto.sh
73 _chruby_dirs 73 _chruby_dirs
74 else 74 else
75 _source_from_omz_settings 75 _source_from_omz_settings
76 _chruby_dirs 76 _chruby_dirs
77 fi 77 fi
78 78
79 function ensure_chruby() { 79 function ensure_chruby() {
80 $(whence chruby) 80 $(whence chruby)
81 } 81 }
82 82
83 function current_ruby() { 83 function current_ruby() {
84 local _ruby 84 local _ruby
85 _ruby="$(chruby |grep \* |tr -d '* ')" 85 _ruby="$(chruby |grep \* |tr -d '* ')"
86 if [[ $(chruby |grep -c \*) -eq 1 ]]; then 86 if [[ $(chruby |grep -c \*) -eq 1 ]]; then
87 echo ${_ruby} 87 echo ${_ruby}
88 else 88 else
89 echo "system" 89 echo "system"
90 fi 90 fi
91 } 91 }
92 92
93 function chruby_prompt_info() { 93 function chruby_prompt_info() {
94 echo "$(current_ruby)" 94 echo "$(current_ruby)"
95 } 95 }
96 96
97 # complete on installed rubies 97 # complete on installed rubies
repos/robbyrussell/oh-my-zsh/plugins/command-not-found/command-not-found.plugin.zsh
1 # Uses the command-not-found package zsh support 1 # Uses the command-not-found package zsh support
2 # as seen in http://www.porcheron.info/command-not-found-for-zsh/ 2 # as seen in http://www.porcheron.info/command-not-found-for-zsh/
3 # this is installed in Ubuntu 3 # this is installed in Ubuntu
4 4
5 [[ -e /etc/zsh_command_not_found ]] && source /etc/zsh_command_not_found 5 [[ -e /etc/zsh_command_not_found ]] && source /etc/zsh_command_not_found
6 6
7 # Arch Linux command-not-found support, you must have package pkgfile installed 7 # Arch Linux command-not-found support, you must have package pkgfile installed
8 # https://wiki.archlinux.org/index.php/Pkgfile#.22Command_not_found.22_hook 8 # https://wiki.archlinux.org/index.php/Pkgfile#.22Command_not_found.22_hook
9 [[ -e /usr/share/doc/pkgfile/command-not-found.zsh ]] && source /usr/share/doc/pkgfile/command-not-found.zsh 9 [[ -e /usr/share/doc/pkgfile/command-not-found.zsh ]] && source /usr/share/doc/pkgfile/command-not-found.zsh
10 10
11 # Fedora command-not-found support 11 # Fedora command-not-found support
12 if [ -f /usr/libexec/pk-command-not-found ]; then 12 if [ -f /usr/libexec/pk-command-not-found ]; then
13 command_not_found_handler () { 13 command_not_found_handler () {
14 runcnf=1 14 runcnf=1
15 retval=127 15 retval=127
16 [ ! -S /var/run/dbus/system_bus_socket ] && runcnf=0 16 [ ! -S /var/run/dbus/system_bus_socket ] && runcnf=0
17 [ ! -x /usr/libexec/packagekitd ] && runcnf=0 17 [ ! -x /usr/libexec/packagekitd ] && runcnf=0
18 if [ $runcnf -eq 1 ] 18 if [ $runcnf -eq 1 ]
19 then 19 then
20 /usr/libexec/pk-command-not-found $@ 20 /usr/libexec/pk-command-not-found $@
21 retval=$? 21 retval=$?
22 fi 22 fi
23 return $retval 23 return $retval
24 } 24 }
25 fi 25 fi
26
27 # OSX command-not-found support
28 # https://github.com/Homebrew/homebrew-command-not-found
29 if type brew &> /dev/null; then
30 if brew command command-not-found-init > /dev/null 2>&1; then
31 eval "$(brew command-not-found-init)";
32 fi
33 fi
26 34
repos/robbyrussell/oh-my-zsh/plugins/dnf/README.md
File was created 1 ## Description
2
3 This plugin makes `dnf` usage easier by adding aliases for the most
4 common commands.
5
6 `dnf` is the new package manager for RPM-based distributions, which
7 replaces `yum`.
8
9 ## Aliases
10
11 | Alias | Command | Description |
12 |-------|-------------------------|--------------------------|
13 | dnfl | `dnf list` | List packages |
14 | dnfli | `dnf list installed` | List installed packages |
15 | dnfgl | `dnf grouplist` | List package groups |
16 | dnfmc | `dnf makecache` | Generate metadata cache |
17 | dnfp | `dnf info` | Show package information |
18 | dnfs | `dnf search` | Search package |
19 | **Use `sudo`** |
20 | dnfu | `sudo dnf upgrade` | Upgrade package |
21 | dnfi | `sudo dnf install` | Install package |
22 | dnfgi | `sudo dnf groupinstall` | Install package group |
23 | dnfr | `sudo dnf remove` | Remove package |
24 | dnfgr | `sudo dnf groupremove` | Remove package group |
25 | dnfc | `sudo dnf clean all` | Clean cache |
26
repos/robbyrussell/oh-my-zsh/plugins/dnf/dnf.plugin.zsh
File was created 1 ## Aliases
2
3 alias dnfl="dnf list" # List packages
4 alias dnfli="dnf list installed" # List installed packages
5 alias dnfgl="dnf grouplist" # List package groups
6 alias dnfmc="dnf makecache" # Generate metadata cache
7 alias dnfp="dnf info" # Show package information
8 alias dnfs="dnf search" # Search package
9
10 alias dnfu="sudo dnf upgrade" # Upgrade package
11 alias dnfi="sudo dnf install" # Install package
12 alias dnfgi="sudo dnf groupinstall" # Install package group
13 alias dnfr="sudo dnf remove" # Remove package
14 alias dnfgr="sudo dnf groupremove" # Remove package group
15 alias dnfc="sudo dnf clean all" # Clean cache
16
repos/robbyrussell/oh-my-zsh/plugins/encode64/encode64.plugin.zsh
1 encode64(){ printf '%s' $1 | base64 } 1 encode64() {
2 decode64(){ printf '%s' $1 | base64 --decode } 2 if [[ $# -eq 0 ]]; then
3 cat | base64
4 else
5 printf '%s' $1 | base64
6 fi
7 }
8
9 decode64() {
10 if [[ $# -eq 0 ]]; then
11 cat | base64 --decode
12 else
13 printf '%s' $1 | base64 --decode
14 fi
15 }
3 alias e64=encode64 16 alias e64=encode64
4 alias d64=decode64 17 alias d64=decode64
5 18
repos/robbyrussell/oh-my-zsh/plugins/forklift/README.md
1 ## forklift 1 ## forklift
2 2
3 Plugin for ForkLift, an FTP application for OS X. 3 Plugin for ForkLift, an FTP application for OS X.
4 4
5 ### Requirements 5 ### Requirements
6 6
7 * [ForkLift](http://forkliftapp.com/forklift/) 7 * [ForkLift](http://www.binarynights.com/forklift/)
8 8
9 ### Usage 9 ### Usage
10 10
11 * If `fl` is called without arguments then the current folder is opened in ForkLift. Is equivalent to `fl .` 11 <code>fl [*file_or_folder*]</code>
12 12
13 * If `fl` is called with a directory as the argument, then that directory is opened in ForkLift
13 * If `fl` is called without arguments then the current folder is opened in ForkLift. This is equivalent to `fl .`.
14
15 * If `fl` is called with a directory as the argument, then that directory is opened in ForkLift. If called with a non-directory file as the argument, then the file's parent directory is opened.
repos/robbyrussell/oh-my-zsh/plugins/git/git.plugin.zsh
1 # Query/use custom command for `git`. 1 # Query/use custom command for `git`.
2 zstyle -s ":vcs_info:git:*:-all-" "command" _omz_git_git_cmd 2 zstyle -s ":vcs_info:git:*:-all-" "command" _omz_git_git_cmd
3 : ${_omz_git_git_cmd:=git} 3 : ${_omz_git_git_cmd:=git}
4 4
5 # 5 #
6 # Functions 6 # Functions
7 # 7 #
8 8
9 # The name of the current branch 9 # The name of the current branch
10 # Back-compatibility wrapper for when this function was defined here in 10 # Back-compatibility wrapper for when this function was defined here in
11 # the plugin, before being pulled in to core lib/git.zsh as git_current_branch() 11 # the plugin, before being pulled in to core lib/git.zsh as git_current_branch()
12 # to fix the core -> git plugin dependency. 12 # to fix the core -> git plugin dependency.
13 function current_branch() { 13 function current_branch() {
14 git_current_branch 14 git_current_branch
15 } 15 }
16 # The list of remotes 16 # The list of remotes
17 function current_repository() { 17 function current_repository() {
18 if ! $_omz_git_git_cmd rev-parse --is-inside-work-tree &> /dev/null; then 18 if ! $_omz_git_git_cmd rev-parse --is-inside-work-tree &> /dev/null; then
19 return 19 return
20 fi 20 fi
21 echo $($_omz_git_git_cmd remote -v | cut -d':' -f 2) 21 echo $($_omz_git_git_cmd remote -v | cut -d':' -f 2)
22 } 22 }
23 # Pretty log messages 23 # Pretty log messages
24 function _git_log_prettily(){ 24 function _git_log_prettily(){
25 if ! [ -z $1 ]; then 25 if ! [ -z $1 ]; then
26 git log --pretty=$1 26 git log --pretty=$1
27 fi 27 fi
28 } 28 }
29 # Warn if the current branch is a WIP 29 # Warn if the current branch is a WIP
30 function work_in_progress() { 30 function work_in_progress() {
31 if $(git log -n 1 2>/dev/null | grep -q -c "\-\-wip\-\-"); then 31 if $(git log -n 1 2>/dev/null | grep -q -c "\-\-wip\-\-"); then
32 echo "WIP!!" 32 echo "WIP!!"
33 fi 33 fi
34 } 34 }
35 35
36 # 36 #
37 # Aliases 37 # Aliases
38 # (sorted alphabetically) 38 # (sorted alphabetically)
39 # 39 #
40 40
41 alias g='git' 41 alias g='git'
42 42
43 alias ga='git add' 43 alias ga='git add'
44 alias gaa='git add --all' 44 alias gaa='git add --all'
45 alias gapa='git add --patch' 45 alias gapa='git add --patch'
46 46
47 alias gb='git branch' 47 alias gb='git branch'
48 alias gba='git branch -a' 48 alias gba='git branch -a'
49 alias gbda='git branch --merged | command grep -vE "^(\*|\s*master\s*$)" | command xargs -n 1 git branch -d' 49 alias gbda='git branch --merged | command grep -vE "^(\*|\s*master\s*$)" | command xargs -n 1 git branch -d'
50 alias gbl='git blame -b -w' 50 alias gbl='git blame -b -w'
51 alias gbnm='git branch --no-merged' 51 alias gbnm='git branch --no-merged'
52 alias gbr='git branch --remote' 52 alias gbr='git branch --remote'
53 alias gbs='git bisect' 53 alias gbs='git bisect'
54 alias gbsb='git bisect bad' 54 alias gbsb='git bisect bad'
55 alias gbsg='git bisect good' 55 alias gbsg='git bisect good'
56 alias gbsr='git bisect reset' 56 alias gbsr='git bisect reset'
57 alias gbss='git bisect start' 57 alias gbss='git bisect start'
58 58
59 alias gc='git commit -v' 59 alias gc='git commit -v'
60 alias gc!='git commit -v --amend' 60 alias gc!='git commit -v --amend'
61 alias gca='git commit -v -a' 61 alias gca='git commit -v -a'
62 alias gca!='git commit -v -a --amend' 62 alias gca!='git commit -v -a --amend'
63 alias gcan!='git commit -v -a -s --no-edit --amend' 63 alias gcan!='git commit -v -a -s --no-edit --amend'
64 alias gcam='git commit -a -m' 64 alias gcam='git commit -a -m'
65 alias gcb='git checkout -b' 65 alias gcb='git checkout -b'
66 alias gcf='git config --list' 66 alias gcf='git config --list'
67 alias gcl='git clone --recursive' 67 alias gcl='git clone --recursive'
68 alias gclean='git clean -fd' 68 alias gclean='git clean -fd'
69 alias gpristine='git reset --hard && git clean -dfx' 69 alias gpristine='git reset --hard && git clean -dfx'
70 alias gcm='git checkout master' 70 alias gcm='git checkout master'
71 alias gcmsg='git commit -m' 71 alias gcmsg='git commit -m'
72 alias gco='git checkout' 72 alias gco='git checkout'
73 alias gcount='git shortlog -sn' 73 alias gcount='git shortlog -sn'
74 compdef gcount=git 74 compdef gcount=git
75 alias gcp='git cherry-pick' 75 alias gcp='git cherry-pick'
76 alias gcs='git commit -S' 76 alias gcs='git commit -S'
77 77
78 alias gd='git diff' 78 alias gd='git diff'
79 alias gdca='git diff --cached' 79 alias gdca='git diff --cached'
80 alias gdct='git describe --tags `git rev-list --tags --max-count=1`' 80 alias gdct='git describe --tags `git rev-list --tags --max-count=1`'
81 alias gdt='git diff-tree --no-commit-id --name-only -r' 81 alias gdt='git diff-tree --no-commit-id --name-only -r'
82 gdv() { git diff -w "$@" | view - } 82 gdv() { git diff -w "$@" | view - }
83 compdef _git gdv=git-diff 83 compdef _git gdv=git-diff
84 alias gdw='git diff --word-diff' 84 alias gdw='git diff --word-diff'
85 85
86 alias gf='git fetch' 86 alias gf='git fetch'
87 alias gfa='git fetch --all --prune' 87 alias gfa='git fetch --all --prune'
88 function gfg() { git ls-files | grep $@ } 88 function gfg() { git ls-files | grep $@ }
89 compdef gfg=grep 89 compdef gfg=grep
90 alias gfo='git fetch origin' 90 alias gfo='git fetch origin'
91 91
92 alias gg='git gui citool' 92 alias gg='git gui citool'
93 alias gga='git gui citool --amend' 93 alias gga='git gui citool --amend'
94 ggf() { 94 ggf() {
95 [[ "$#" != 1 ]] && local b="$(git_current_branch)" 95 [[ "$#" != 1 ]] && local b="$(git_current_branch)"
96 git push --force origin "${b:=$1}" 96 git push --force origin "${b:=$1}"
97 } 97 }
98 compdef _git ggf=git-checkout 98 compdef _git ggf=git-checkout
99 ggl() { 99 ggl() {
100 if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then 100 if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
101 git pull origin "${*}" 101 git pull origin "${*}"
102 else 102 else
103 [[ "$#" == 0 ]] && local b="$(git_current_branch)" 103 [[ "$#" == 0 ]] && local b="$(git_current_branch)"
104 git pull origin "${b:=$1}" 104 git pull origin "${b:=$1}"
105 fi 105 fi
106 } 106 }
107 compdef _git ggl=git-checkout 107 compdef _git ggl=git-checkout
108 alias ggpull='git pull origin $(git_current_branch)' 108 alias ggpull='git pull origin $(git_current_branch)'
109 compdef _git ggpull=git-checkout 109 compdef _git ggpull=git-checkout
110 ggp() { 110 ggp() {
111 if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then 111 if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
112 git push origin "${*}" 112 git push origin "${*}"
113 else 113 else
114 [[ "$#" == 0 ]] && local b="$(git_current_branch)" 114 [[ "$#" == 0 ]] && local b="$(git_current_branch)"
115 git push origin "${b:=$1}" 115 git push origin "${b:=$1}"
116 fi 116 fi
117 } 117 }
118 compdef _git ggp=git-checkout 118 compdef _git ggp=git-checkout
119 alias ggpush='git push origin $(git_current_branch)' 119 alias ggpush='git push origin $(git_current_branch)'
120 compdef _git ggpush=git-checkout 120 compdef _git ggpush=git-checkout
121 ggpnp() { 121 ggpnp() {
122 if [[ "$#" == 0 ]]; then 122 if [[ "$#" == 0 ]]; then
123 ggl && ggp 123 ggl && ggp
124 else 124 else
125 ggl "${*}" && ggp "${*}" 125 ggl "${*}" && ggp "${*}"
126 fi 126 fi
127 } 127 }
128 compdef _git ggpnp=git-checkout 128 compdef _git ggpnp=git-checkout
129 alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)' 129 alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)'
130 ggu() { 130 ggu() {
131 [[ "$#" != 1 ]] && local b="$(git_current_branch)" 131 [[ "$#" != 1 ]] && local b="$(git_current_branch)"
132 git pull --rebase origin "${b:=$1}" 132 git pull --rebase origin "${b:=$1}"
133 } 133 }
134 compdef _git ggu=git-checkout 134 compdef _git ggu=git-checkout
135 alias ggpur='ggu' 135 alias ggpur='ggu'
136 compdef _git ggpur=git-checkout 136 compdef _git ggpur=git-checkout
137 137
138 alias gignore='git update-index --assume-unchanged' 138 alias gignore='git update-index --assume-unchanged'
139 alias gignored='git ls-files -v | grep "^[[:lower:]]"' 139 alias gignored='git ls-files -v | grep "^[[:lower:]]"'
140 alias git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk' 140 alias git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk'
141 compdef git-svn-dcommit-push=git 141 compdef git-svn-dcommit-push=git
142 142
143 alias gk='\gitk --all --branches' 143 alias gk='\gitk --all --branches'
144 compdef _git gk='gitk' 144 compdef _git gk='gitk'
145 alias gke='\gitk --all $(git log -g --pretty=format:%h)' 145 alias gke='\gitk --all $(git log -g --pretty=format:%h)'
146 compdef _git gke='gitk' 146 compdef _git gke='gitk'
147 147
148 alias gl='git pull' 148 alias gl='git pull'
149 alias glg='git log --stat --color' 149 alias glg='git log --stat --color'
150 alias glgp='git log --stat --color -p' 150 alias glgp='git log --stat --color -p'
151 alias glgg='git log --graph --color' 151 alias glgg='git log --graph --color'
152 alias glgga='git log --graph --decorate --all' 152 alias glgga='git log --graph --decorate --all'
153 alias glgm='git log --graph --max-count=10' 153 alias glgm='git log --graph --max-count=10'
154 alias glo='git log --oneline --decorate --color' 154 alias glo='git log --oneline --decorate --color'
155 alias glol="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" 155 alias glol="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
156 alias glola="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all" 156 alias glola="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all"
157 alias glog='git log --oneline --decorate --color --graph' 157 alias glog='git log --oneline --decorate --color --graph'
158 alias glp="_git_log_prettily" 158 alias glp="_git_log_prettily"
159 compdef _git glp=git-log 159 compdef _git glp=git-log
160 160
161 alias gm='git merge' 161 alias gm='git merge'
162 alias gmom='git merge origin/master' 162 alias gmom='git merge origin/master'
163 alias gmt='git mergetool --no-prompt' 163 alias gmt='git mergetool --no-prompt'
164 alias gmtvim='git mergetool --no-prompt --tool=vimdiff' 164 alias gmtvim='git mergetool --no-prompt --tool=vimdiff'
165 alias gmum='git merge upstream/master' 165 alias gmum='git merge upstream/master'
166 166
167 alias gp='git push' 167 alias gp='git push'
168 alias gpd='git push --dry-run' 168 alias gpd='git push --dry-run'
169 alias gpoat='git push origin --all && git push origin --tags' 169 alias gpoat='git push origin --all && git push origin --tags'
170 compdef _git gpoat=git-push 170 compdef _git gpoat=git-push
171 alias gpu='git push upstream' 171 alias gpu='git push upstream'
172 alias gpv='git push -v' 172 alias gpv='git push -v'
173 173
174 alias gr='git remote' 174 alias gr='git remote'
175 alias gra='git remote add' 175 alias gra='git remote add'
176 alias grb='git rebase' 176 alias grb='git rebase'
177 alias grba='git rebase --abort' 177 alias grba='git rebase --abort'
178 alias grbc='git rebase --continue' 178 alias grbc='git rebase --continue'
179 alias grbi='git rebase -i' 179 alias grbi='git rebase -i'
180 alias grbm='git rebase master' 180 alias grbm='git rebase master'
181 alias grbs='git rebase --skip' 181 alias grbs='git rebase --skip'
182 alias grh='git reset HEAD' 182 alias grh='git reset HEAD'
183 alias grhh='git reset HEAD --hard' 183 alias grhh='git reset HEAD --hard'
184 alias grmv='git remote rename' 184 alias grmv='git remote rename'
185 alias grrm='git remote remove' 185 alias grrm='git remote remove'
186 alias grset='git remote set-url' 186 alias grset='git remote set-url'
187 alias grt='cd $(git rev-parse --show-toplevel || echo ".")' 187 alias grt='cd $(git rev-parse --show-toplevel || echo ".")'
188 alias gru='git reset --' 188 alias gru='git reset --'
189 alias grup='git remote update' 189 alias grup='git remote update'
190 alias grv='git remote -v' 190 alias grv='git remote -v'
191 191
192 alias gsb='git status -sb' 192 alias gsb='git status -sb'
193 alias gsd='git svn dcommit' 193 alias gsd='git svn dcommit'
194 alias gsi='git submodule init' 194 alias gsi='git submodule init'
195 alias gsps='git show --pretty=short --show-signature' 195 alias gsps='git show --pretty=short --show-signature'
196 alias gsr='git svn rebase' 196 alias gsr='git svn rebase'
197 alias gss='git status -s' 197 alias gss='git status -s'
198 alias gst='git status' 198 alias gst='git status'
199 alias gsta='git stash' 199 alias gsta='git stash'
200 alias gstaa='git stash apply' 200 alias gstaa='git stash apply'
201 alias gstd='git stash drop' 201 alias gstd='git stash drop'
202 alias gstl='git stash list' 202 alias gstl='git stash list'
203 alias gstp='git stash pop' 203 alias gstp='git stash pop'
204 alias gsts='git stash show --text' 204 alias gsts='git stash show --text'
205 alias gsu='git submodule update' 205 alias gsu='git submodule update'
206 206
207 alias gts='git tag -s' 207 alias gts='git tag -s'
208 alias gtv='git tag | sort -V' 208 alias gtv='git tag | sort -V'
209 209
210 alias gunignore='git update-index --no-assume-unchanged' 210 alias gunignore='git update-index --no-assume-unchanged'
211 alias gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1' 211 alias gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1'
212 alias gup='git pull --rebase' 212 alias gup='git pull --rebase'
213 alias gupv='git pull --rebase -v' 213 alias gupv='git pull --rebase -v'
214 alias glum='git pull upstream master' 214 alias glum='git pull upstream master'
215 215
216 alias gvt='git verify-tag'
217
218 alias gwch='git whatchanged -p --abbrev-commit --pretty=medium' 216 alias gwch='git whatchanged -p --abbrev-commit --pretty=medium'
219 alias gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit -m "--wip--"' 217 alias gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit -m "--wip--"'
220 218
repos/robbyrussell/oh-my-zsh/plugins/gitignore/gitignore.plugin.zsh
1 function gi() { curl -sL https://www.gitignore.io/api/$@ ;} 1 function gi() { curl -sL https://www.gitignore.io/api/${(j:,:)@} }
2 2
3 _gitignoreio_get_command_list() { 3 _gitignoreio_get_command_list() {
4 curl -sL https://www.gitignore.io/api/list | tr "," "\n" 4 curl -sL https://www.gitignore.io/api/list | tr "," "\n"
5 } 5 }
6 6
7 _gitignoreio () { 7 _gitignoreio () {
8 compset -P '*,' 8 compset -P '*,'
9 compadd -S '' `_gitignoreio_get_command_list` 9 compadd -S '' `_gitignoreio_get_command_list`
10 } 10 }
11 11
12 compdef _gitignoreio gi 12 compdef _gitignoreio gi
13 13
repos/robbyrussell/oh-my-zsh/plugins/pylint/pylint.plugin.zsh
1 # Aliases 1 # Aliases
2 alias pylint-quick='pylint --reports=n --include-ids=y'
3 compdef _pylint-quick pylint-quick='pylint --reports=n --include-ids=y'
2 alias pylint-quick='pylint --reports=n'
repos/robbyrussell/oh-my-zsh/plugins/vault/README.md
File was created 1 ## Vault (https://www.vaultproject.io) autocomplete plugin
2
3 - Adds autocomplete options for all vault commands.
4
5 ####Show help for all commands
6 ![General Help](http://i.imgur.com/yv5Db1r.png "Help for all commands")
7
8
9 ####Create new Vault token
10 ![Create token](http://i.imgur.com/xMegNgh.png "Create token")
11
12
13 ####Enable audit backends
14 ![Audit backends](http://i.imgur.com/fKLeiSF.png "Audit backends")
15
16
17
18 Crafted with <3 by Valentin Bud ([@valentinbud](https://twitter.com/valentinbud))
repos/robbyrussell/oh-my-zsh/plugins/vault/_vault
File was created 1 #compdef vault
2
3 typeset -a main_args
4 main_args=(
5 '(-version)-version[Prints the Vault version]'
6 '(-help)-help[Prints Vault Help]'
7 )
8
9 typeset -a general_args
10 general_args=(
11 '(-help)-help[Prints Help]'
12 '(-address)-address=-[The address of the Vault server. Overrides the VAULT_ADDR environment variable if set.]:address:'
13 '(-ca-cert)-ca-cert=-[Path to a PEM encoded CA cert file to use to verify the Vault server SSL certificate. Overrides the VAULT_CACERT environment variable if set.]:file:_files -g "*.pem"'
14 '(-ca-path)-ca-path=-[Path to a directory of PEM encoded CA cert files to verify the Vault server SSL certificate. If both -ca-cert and -ca-path are specified, -ca-path is used.Overrides the VAULT_CAPATH environment variable if set.]:directory:_directories'
15 '(-client-cert)-client-cert=-[Path to a PEM encoded client certificate for TLS authentication to the Vault server. Must also specify -client-key. Overrides the VAULT_CLIENT_CERT environment variable if set.]:file:_files -g "*.pem"'
16 '(-client-key)-client-key=-[Path to an unencrypted PEM encoded private key matching the client certificate from -client-cert. Overrides the VAULT_CLIENT_KEY environment variable if set.]:file:_files -g "*.pem"'
17 '(-tls-skip-verify)-tls-skip-verify[Do not verify TLS certificate. This is highly not recommended. Verification will also be skipped if VAULT_SKIP_VERIFY is set.]'
18 )
19
20 typeset -a audit_enable_args
21 audit_enable_args=(
22 '(-description)-description=-[A human-friendly description for the backend. This shows up only when querying the enabled backends.]:description:'
23 '(-id)-id=-[Specify a unique ID for this audit backend. This is purely for referencing this audit backend. By default this will be the backend type.]:id:'
24 )
25
26 typeset -a auth_args
27 auth_args=(
28 '(-method)-method=-[Outputs help for the authentication method with the given name for the remote server. If this authentication method is not available, exit with code 1.]:method:(cert ldap github userpass app-id)'
29 '(-method-help)-method-help[If set, the help for the selected method will be shown.]'
30 '(-methods)-methods[List the available auth methods.]'
31 '(-no-verify)-no-verify[Do not verify the token after creation; avoids a use count]'
32 )
33
34 typeset -a auth_enable_args
35 auth_enable_args=(
36 '(-description)-description=-[Human-friendly description of the purpose for the auth provider. This shows up in the auth-list command.]:description:'
37 '(-path)-path=-[Mount point for the auth provider. This defaults to the type of the mount. This will make the auth provider available at "/auth/<path>"]:path:'
38 )
39
40 typeset -a init_args
41 init_args=(
42 '(-key-shares)-key-shares=-[(default: 5) The number of key shares to split the master key into.]:keyshares:'
43 '(-key-threshold)-key-threshold=-[(default: 3) The number of key shares required to reconstruct the master key.]:keythreshold:'
44 '(-pgp-keys)-pgp-keys[If provided, must be a comma-separated list of files on disk containing binary- or base64-format public PGP keys. The number of files must match "key-shares". The output unseal keys will encrypted and hex-encoded, in order, with the given public keys. If you want to use them with the "vault unseal" command, you will need to hex decode and decrypt; this will be the plaintext unseal key.]:pgpkeys:_files'
45 )
46
47 typeset -a mount_tune_args
48 mount_tune_args=(
49 '(-default-lease-ttl)-default-lease-ttl=-[Default lease time-to-live for this backend. If not specified, uses the system default, or the previously set value. Set to "system" to explicitly set it to use the system default.]:defaultleasettl:'
50 '(-max-lease-ttl)-max-lease-ttl=-[Max lease time-to-live for this backend. If not specified, uses the system default, or the previously set value. Set to "system" to explicitly set it to use the system default.]:maxleasettl:'
51 )
52
53 typeset -a mount_args
54 mount_args=(
55 $mount_tune_args
56 '(-path)-path=-[Mount point for the logical backend. This defauls to the type of the mount.]:path:'
57 '(-description)-description=-[Human-friendly description of the purpose for the mount. This shows up in the mounts command.]:description:'
58 )
59
60 typeset -a rekey_args
61 rekey_args=(
62 $init_args
63 '(-init)-init[Initialize the rekey operation by setting the desired number of shares and the key threshold. This can only be done if no rekey is already initiated.]:init:'
64 '(-cancel)-cancel[Reset the rekey process by throwing away prior keys and the rekey configuration.]:cancel:'
65 '(-status)-status[Prints the status of the current rekey operation. This can be used to see the status without attempting to provide an unseal key.]:status:'
66 )
67
68 typeset -a ssh_args
69 ssh_args=(
70 '(-role)-role[Role to be used to create the key. ]:role:'
71 '(-no-exec)-no-exec[Shows the credentials but does not establish connection.]:noexec:'
72 '(-mount-point)-mount-point[Mount point of SSH backend. If the backend is mounted at "ssh", which is the default as well, this parameter can be skipped.]:mountpoint:'
73 '(-format)-format[If no-exec option is enabled, then the credentials will be printed out and SSH connection will not be established. The format of the output can be "json" or "table". JSON output is useful when writing scripts. Default is "table".]:format:(json table)'
74 )
75
76 typeset -a token_create_args
77 token_create_args=(
78 '(-id)-id=-[The token value that clients will use to authenticate with vault. If not provided this defaults to a 36 character UUID. A root token is required to specify the ID of a token.]:id:'
79 '(-display-name)-display-name=-[A display name to associate with this token. This is a non-security sensitive value used to help identify created secrets, i.e. prefixes.]:displayname:'
80 '(-ttl)-ttl=-[TTL to associate with the token. This option enables the tokens to be renewable.]:ttl:'
81 '*-metadata=-[Metadata to associate with the token. This shows up in the audit log. This can be specified multiple times.]:metadata:'
82 '(-orphan)-orphan[If specified, the token will have no parent. Only root tokens can create orphan tokens. This prevents the new token from being revoked with your token.]:orphan:'
83 '(-no-default-policy)-no-default-policy[If specified, the token will not have the "default" policy included in its policy set.]:nodefaultpolicy:'
84 '*-policy=-[Policy to associate with this token. This can be specified multiple times.]:policy:__vault_policies'
85 '(-use-limit)-use-limit=-[The number of times this token can be used until it is automatically revoked.]:uselimit:'
86 '(-format)-format=-[The format for output. By default it is a whitespace-delimited table. This can also be json.]:format:(json table)'
87 )
88
89 typeset -a server_args
90 server_args=(
91 '*-config=-[Path to the configuration file or directory. This can be specified multiple times. If it is a directory, all files with a ".hcl" or ".json" suffix will be loaded.]:config:_files'
92 '-dev[Enables Dev mode. In this mode, Vault is completely in-memory and unsealed. Do not run the Dev server in production!]:dev:'
93 '-log-level=-[Log verbosity. Defaults to "info", will be outputtedto stderr. Supported values: "trace", "debug", "info", "warn", "err"]:loglevel:(trace debug info warn err)'
94 )
95
96 _vault_audit-list() {
97 _arguments : \
98 ${general_args[@]} && ret=0
99 }
100
101 _vault_audit-disable() {
102 # vault audit-list doesn't print the backend id so for now
103 # no *smart* autocompletion for this subcommand.
104 _arguments : \
105 ${general_args[@]} \
106 ':::(file syslog)' && ret=0
107 }
108
109 _vault_audit-enable() {
110 _arguments : \
111 ${general_args[@]} \
112 ${audit_enable_args[@]} \
113 ': :->backends' \
114 '*:: :->backendconfig' && ret=0
115
116 case $state in
117 backends)
118 local -a backends
119 backends=(
120 'file:The "file" audit backend writes audit logs to a file.'
121 'syslog:The "syslog" audit backend writes audit logs to syslog.'
122 )
123 _describe -t backends 'vault audit backends' backends && ret=0
124 ;;
125 backendconfig)
126 case ${line[1]} in
127 file)
128 _values -w "Audit Backend File" \
129 'path[(required) - The path to where the file will be written. If this path exists, the audit backend will append to it.]:file:_files' \
130 'log_raw[(optional) Should security sensitive information be logged raw. Defaults to "false".]:log_raw:(true false)' && ret=0
131 ;;
132 syslog)
133 _values -w "Audit Backend Syslog" \
134 'facility[(optional) - The syslog facility to use. Defaults to "AUTH".]:facility:(kern user mail daemon auth syslog lpr news uucp authpriv ftp cron local0 local1 local2 local3 local4 local5 local6 local7)' \
135 'tag[(optional) - The syslog tag to use. Defaults to "vault".]:tag:' \
136 'log_raw[(optional) Should security sensitive information be logged raw.]:log_raw:(true false)' && ret=0
137 ;;
138 esac
139 ;;
140 esac
141 }
142
143 _vault_auth() {
144 _arguments : \
145 ${general_args[@]} \
146 ${auth_args[@]} && ret=0
147 }
148
149 _vault_auth-enable() {
150 _arguments : \
151 ${general_args[@]} \
152 ${auth_enable_args[@]} \
153 ':::(cert ldap github userpass app-id)' && ret=0
154 }
155
156 __vault_auth_methods() {
157 local -a authmethods
158 authmethods=($(vault auth -methods | awk 'NR>1{split ($1,a,"/"); print a[1]":["$2"]"}'))
159 _describe -t authmethods 'authmethods' authmethods && ret=0
160 }
161
162 _vault_auth-disable() {
163 _arguments : \
164 ${general_args[@]} \
165 ':::__vault_auth_methods' && ret=0
166
167 }
168
169 _vault_init() {
170 _arguments : \
171 ${general_args[@]} \
172 ${init_args[@]} && ret=0
173 }
174
175 _vault_key-status() {
176 _arguments : \
177 ${general_args[@]} && ret=0
178 }
179
180 __vault_mounts() {
181 local -a mounts
182 mounts=($(vault mounts | awk 'NR>1{split ($1,a,"/"); print a[1]":["$2"]"}'))
183 _describe -t mounts 'mounts' mounts && ret=0
184 }
185
186 _vault_mounts() {
187 _arguments : \
188 ${general_args[@]} && ret=0
189 }
190
191 _vault_mount() {
192 # to find out how many types of backens are there
193 _arguments : \
194 ${general_args[@]} \
195 ${mount_args[@]} \
196 ':::(generic ssh)' && ret=0
197 }
198
199 _vault_mount-tune() {
200 _arguments : \
201 ${general_args[@]} \
202 ${mount_tune_args[@]} \
203 ':::__vault_mounts' && ret=0
204 }
205
206 _vault_unmount() {
207 _arguments : \
208 ${general_args[@]} \
209 ':::__vault_mounts' && ret=0
210 }
211
212 _vault_remount() {
213 _arguments : \
214 ${general_args[@]} \
215 ':::__vault_mounts' \
216 ':::' && ret=0
217 }
218
219 __vault_policies() {
220 local -a policies
221 policies=($(vault policies | awk '{print $1":["$1"]"}'))
222 _describe -t policies 'policies' policies && ret=0
223 }
224
225 _vault_policies() {
226 _arguments : \
227 ${general_args[@]} \
228 ':::__vault_policies' && ret=0
229 }
230
231 _vault_policy-delete() {
232 _arguments : \
233 ${general_args[@]} \
234 ':::__vault_policies' && ret=0
235 }
236
237 _vault_policy-write() {
238 _arguments : \
239 ${general_args[@]} \
240 ': ::' \
241 '::policy:_files' && ret=0
242 }
243
244 _vault_status() {
245 _arguments : \
246 ${general_args[@]} && ret=0
247 }
248
249 _vault_rekey() {
250 _arguments : \
251 ${general_args[@]} \
252 ${rekey_args[@]} \
253 ': ::' && ret=0
254 }
255
256 _vault_rotate() {
257 _arguments : \
258 ${general_args[@]} && ret=0
259 }
260
261 _vault_seal() {
262 _arguments : \
263 ${general_args[@]} && ret=0
264 }
265
266 _vault_ssh() {
267 _arguments : \
268 ${general_args[@]} \
269 ${ssh_args[@]} \
270 ': ::' && ret=0
271 }
272
273 _vault_token-create() {
274 _arguments : \
275 ${general_args[@]} \
276 ${token_create_args[@]} && ret=0
277 }
278
279 _vault_token-renew() {
280 _arguments : \
281 ${general_args[@]} \
282 '(-format)-format=-[The format for output. By default it is a whitespace-delimited table. This can also be json.]:format:(json table)' \
283 ': ::' \
284 ': ::' && ret=0
285 }
286
287 _vault_token-revoke() {
288 _arguments : \
289 ${general_args[@]} \
290 '(-mode)-mode=-[The type of revocation to do. See the documentation above for more information.]:mode:( orphan path)' \
291 ': ::' && ret=0
292 }
293
294 _vault_unseal() {
295 _arguments : \
296 ${general_args[@]} \
297 '(-reset)-reset[Reset the unsealing process by throwing away prior keys in process to unseal the vault.]:reset:' \
298 ': ::' && ret=0
299 }
300
301 _vault_version() {
302 # no args
303 }
304
305 _vault_delete() {
306 _arguments : \
307 ${general_args[@]} \
308 ': ::' && ret=0
309 }
310
311 _vault_path-help() {
312 _arguments : \
313 ${general_args[@]} \
314 ': ::' && ret=0
315 }
316
317 _vault_revoke() {
318 _arguments : \
319 ${general_args[@]} \
320 '(-format)-format=-[The format for output. By default it is a whitespace-delimited table. This can also be json.]:format:(json table)' \
321 ': ::' \
322 ': ::' && ret=0
323 }
324
325 _vault_server() {
326 _arguments : \
327 ${server_args[@]} && ret=0
328
329 }
330
331 _vault_write() {
332 _arguments : \
333 ${general_args[@]} \
334 '(-f -force)'{-f,-force}'[Force the write to continue without any data values specified. This allows writing to keys that do not need or expect any fields to be specified.]:force:' \
335 ': ::' \
336 ': ::' && ret=0
337 }
338
339 _vault_read() {
340 _arguments : \
341 ${general_args[@]} \
342 '(-format)-format=-[The format for output. By default it is a whitespace-delimited table. This can also be json.]:format:(json table)' \
343 '(-field)-field=-[If included, the raw value of the specified field will be output raw to stdout.]:field:' \
344 ': ::' && ret=0
345 }
346
347 _vault_commands() {
348 local -a commands
349
350 commands=(
351 "delete":"Delete operation on secrets in Vault"
352 "path-help":"Look up the help for a path"
353 "read":"Read data or secrets from Vault"
354 "renew":"Renew the lease of a secret"
355 "revoke":"Revoke a secret"
356 "server":"Start a Vault server"
357 "status":"Outputs status of whether Vault is sealed and if HA mode is enabled"
358 "write":"Write secrets or configuration into Vault"
359 "audit-disable":"Disable an audit backend"
360 "audit-enable":"Enable an audit backend"
361 "audit-list":"Lists enabled audit backends in Vault"
362 "auth":"Prints information about how to authenticate with Vault"
363 "auth-disable":"Disable an auth provider"
364 "auth-enable":"Enable a new auth provider"
365 "init":"Initialize a new Vault server"
366 "key-status":"Provides information about the active encryption key"
367 "mount":"Mount a logical backend"
368 "mount-tune":"Tune mount configuration parameters"
369 "mounts":"Lists mounted backends in Vault"
370 "policies":"List the policies on the server"
371 "policy-delete":"Delete a policy from the server"
372 "policy-write":"Write a policy to the server"
373 "rekey":"Rekeys Vault to generate new unseal keys"
374 "remount":"Remount a secret backend to a new path"
375 "rotate":"Rotates the backend encryption key used to persist data"
376 "seal":"Seals the vault server"
377 "ssh":"Initiate a SSH session"
378 "token-create":"Create a new auth token"
379 "token-renew":"Renew an auth token if there is an associated lease"
380 "token-revoke":"Revoke one or more auth tokens"
381 "unmount":"Unmount a secret backend"
382 "unseal":"Unseals the vault server"
383 "version":"Prints the Vault version"
384 )
385
386 _describe -t commands 'vault command' commands && ret=0
387 }
388
389 local curcontext=$curcontext ret=1
390 _arguments : \
391 ${main_args[@]} \
392 '*:: :->subcommands' && ret=0
393 if ((CURRENT == 1 )); then
394 _vault_commands && ret=0
395 fi
396 if [[ $state == subcommands ]]; then
397 # (( CURRENT -- ))
398 curcontext="${curcontext%:*:*}:vault-$words[1]:"
399 _call_function ret _vault_$words[1]
400 fi
401
repos/robbyrussell/oh-my-zsh/plugins/zsh-navigation-tools/.config/znt/n-cd.conf
1 # Hotlist 1 # Hotlist
2 # Try to use $ZSH_VERSION, e.g. /usr/share/zsh/$ZSH_VERSION/functions
2 local hotlist 3 local hotlist
3 hotlist=( 4 hotlist=(
4 ~/.config/znt 5 ~/.config/znt
5 /usr/share/zsh/site-functions 6 /usr/share/zsh/site-functions
6 /usr/share/zsh 7 /usr/share/zsh
7 /usr/local/share/zsh/site-functions 8 /usr/local/share/zsh/site-functions
8 /usr/local/share/zsh 9 /usr/local/share/zsh
9 /usr/local/bin 10 /usr/local/bin
10 /usr/lib
11 ) 11 )
12 12
13 # Suppress adding (to directory stack) directories visited by n-cd 13 # Suppress adding (to directory stack) directories visited by n-cd
14 # Value 0 is the default (directories will be added to dirstack) 14 # Value 0 is the default (directories will be added to dirstack)
15 local NCD_DONT_PUSHD=0 15 local NCD_DONT_PUSHD=0
16 16
17 # How should be current element of the list drawn. Possible values: reverse, 17 # How should be current element of the list drawn. Possible values: reverse,
18 # underline. Default (without option set) is reverse 18 # underline. Default (without option set) is reverse
19 # On Linux virtual terminal this will be enforced to reverse (because of poor 19 # On Linux virtual terminal this will be enforced to reverse (because of poor
20 # underline support on that terminal) 20 # underline support on that terminal)
21 # local active_text=underline 21 # local active_text=underline
22 22
23 # Colorize last segments of the paths 23 # Colorize last segments of the paths
24 # (#s) is ^, (#e) is $, # is *, ## is + (comparing to regex) 24 # (#s) is ^, (#e) is $, # is *, ## is + (comparing to regex)
25 local NLIST_COLORING_PATTERN="[a-zA-Z0-9 ._-]##/#(#e)" 25 local NLIST_COLORING_PATTERN="[a-zA-Z0-9 ._-]##/#(#e)"
26 local NLIST_COLORING_COLOR=$'\x1b[00;33m' 26 local NLIST_COLORING_COLOR=$'\x1b[00;33m'
repos/robbyrussell/oh-my-zsh/plugins/zsh-navigation-tools/README.md
1 # Zsh Navigation Tools 1 # Zsh Navigation Tools
2 2
3 http://imageshack.com/a/img633/7967/ps6rKR.png 3 http://imageshack.com/a/img633/7967/ps6rKR.png
4 4
5 Set of tools like n-history – multi-word history searcher, n-cd – directory 5 Set of tools like n-history – multi-word history searcher, n-cd – directory
6 bookmark manager, n-kill – htop like kill utility, and more. Based on 6 bookmark manager, n-kill – htop like kill utility, and more. Based on
7 n-list, a tool generating selectable curses-based list of elements that has 7 n-list, a tool generating selectable curses-based list of elements that has
8 access to current Zsh session, i.e. has broad capabilities to work together 8 access to current Zsh session, i.e. has broad capabilities to work together
9 with it. Feature highlights include incremental multi-word searching, ANSI 9 with it. Feature highlights include incremental multi-word searching, ANSI
10 coloring, unique mode, horizontal scroll, non-selectable elements, grepping and 10 coloring, unique mode, horizontal scroll, non-selectable elements, grepping and
11 various integrations with Zsh. 11 various integrations with Zsh.
12 12
13 ## History Widget 13 ## History Widget
14 14
15 To have n-history as multi-word incremental searcher bound to Ctrl-R copy znt-* 15 To have n-history as multi-word incremental searcher bound to Ctrl-R copy znt-*
16 files into the */site-functions dir (unless you use Oh My Zsh) and 16 files into the */site-functions dir (unless you use Oh My Zsh) and
17 add: 17 add:
18 18
19 autoload znt-history-widget 19 autoload znt-history-widget
20 zle -N znt-history-widget 20 zle -N znt-history-widget
21 bindkey "^R" znt-history-widget 21 bindkey "^R" znt-history-widget
22 22
23 to .zshrc. This is done automatically when using Oh My Zsh. Two other 23 to .zshrc. This is done automatically when using Oh My Zsh. Two other
24 widgets exist, znt-cd-widget and znt-kill-widget, they can be too assigned 24 widgets exist, znt-cd-widget and znt-kill-widget, they can be too assigned
25 to key combinations (no need for autoload when using Oh My Zsh): 25 to key combinations (no need for autoload when using Oh My Zsh):
26 26
27 zle -N znt-cd-widget 27 zle -N znt-cd-widget
28 bindkey "^T" znt-cd-widget 28 bindkey "^A" znt-cd-widget
29 zle -N znt-kill-widget 29 zle -N znt-kill-widget
30 bindkey "^Y" znt-kill-widget 30 bindkey "^Y" znt-kill-widget
31 31
32 Oh My Zsh stores history into ~/.zsh_history. When you switch to OMZ you could 32 Oh My Zsh stores history into ~/.zsh_history. When you switch to OMZ you could
33 want to copy your previous data (from e.g. ~/.zhistory) into the new location. 33 want to copy your previous data (from e.g. ~/.zhistory) into the new location.
34 34
35 ## Introduction 35 ## Introduction
36 36
37 The tools are: 37 The tools are:
38 38
39 - n-aliases - browses aliases, relegates editing to vared 39 - n-aliases - browses aliases, relegates editing to vared
40 - n-cd - browses dirstack and bookmarked directories, allows to enter selected directory 40 - n-cd - browses dirstack and bookmarked directories, allows to enter selected directory
41 - n-functions - browses functions, relegates editing to zed or vared 41 - n-functions - browses functions, relegates editing to zed or vared
42 - n-history - browses history, allows to edit and run commands from it 42 - n-history - browses history, allows to edit and run commands from it
43 - n-kill - browses processes list, allows to send signal to selected process 43 - n-kill - browses processes list, allows to send signal to selected process
44 - n-env - browses environment, relegates editing to vared 44 - n-env - browses environment, relegates editing to vared
45 - n-options - browses options, allows to toggle their state 45 - n-options - browses options, allows to toggle their state
46 - n-panelize - loads output of given command into the list for browsing 46 - n-panelize - loads output of given command into the list for browsing
47 47
48 All tools support horizontal scroll with <,>, {,}, h,l or left and right 48 All tools support horizontal scroll with <,>, {,}, h,l or left and right
49 cursors. Other keys are: 49 cursors. Other keys are:
50 50
51 - [,] - jump directory bookmarks in n-cd and typical signals in n-kill 51 - [,] - jump directory bookmarks in n-cd and typical signals in n-kill
52 - Ctrl-d, Ctrl-u - half page up or down 52 - Ctrl-d, Ctrl-u - half page up or down
53 - Ctrl-p, Ctrl-n - previous and next (also done with vim's j,k) 53 - Ctrl-p, Ctrl-n - previous and next (also done with vim's j,k)
54 - Ctrl-l - redraw of whole display 54 - Ctrl-l - redraw of whole display
55 - g, G - beginning and end of the list 55 - g, G - beginning and end of the list
56 - Ctrl-o, o - enter uniq mode (no duplicate lines) 56 - Ctrl-o, o - enter uniq mode (no duplicate lines)
57 - / - start incremental search 57 - / - start incremental search
58 - Enter - finish incremental search, retaining filter 58 - Enter - finish incremental search, retaining filter
59 - Esc - exit incremental search, clearing filter 59 - Esc - exit incremental search, clearing filter
60 - Ctrl-w (in incremental search) - delete whole word 60 - Ctrl-w (in incremental search) - delete whole word
61 - Ctrl-k (in incremental search) - delete whole line 61 - Ctrl-k (in incremental search) - delete whole line
62 62
63 ## Programming 63 ## Programming
64 64
65 The function n-list is used as follows: 65 The function n-list is used as follows:
66 66
67 n-list {element1} [element2] ... [elementN] 67 n-list {element1} [element2] ... [elementN]
68 68
69 This is all that is needed to be done to have the features like ANSI coloring, 69 This is all that is needed to be done to have the features like ANSI coloring,
70 incremental multi-word search, unique mode, horizontal scroll, non-selectable 70 incremental multi-word search, unique mode, horizontal scroll, non-selectable
71 elements (grepping is done outside n-list, see the tools for how it can be 71 elements (grepping is done outside n-list, see the tools for how it can be
72 done). To set up non-selectable entries add their indices into array 72 done). To set up non-selectable entries add their indices into array
73 NLIST_NONSELECTABLE_ELEMENTS: 73 NLIST_NONSELECTABLE_ELEMENTS:
74 74
75 typeset -a NLIST_NONSELECTABLE_ELEMENTS 75 typeset -a NLIST_NONSELECTABLE_ELEMENTS
76 NLIST_NONSELECTABLE_ELEMENTS=( 1 ) 76 NLIST_NONSELECTABLE_ELEMENTS=( 1 )
77 77
78 Result is stored as $reply[REPLY] ($ isn't needed before REPLY because 78 Result is stored as $reply[REPLY] ($ isn't needed before REPLY because
79 of arithmetic context inside []). The returned array might be different from 79 of arithmetic context inside []). The returned array might be different from
80 input arguments as n-list can process them via incremental search or uniq 80 input arguments as n-list can process them via incremental search or uniq
81 mode. $REPLY is the index in that possibly processed array. If $REPLY 81 mode. $REPLY is the index in that possibly processed array. If $REPLY
82 equals -1 it means that no selection have been made (user quitted via q 82 equals -1 it means that no selection have been made (user quitted via q
83 key). 83 key).
84 84
85 To set up entries that can be jumped to with [,] keys add their indices to 85 To set up entries that can be jumped to with [,] keys add their indices to
86 NLIST_HOP_INDEXES array: 86 NLIST_HOP_INDEXES array:
87 87
88 typeset -a NLIST_HOP_INDEXES 88 typeset -a NLIST_HOP_INDEXES
89 NLIST_HOP_INDEXES=( 1 10 ) 89 NLIST_HOP_INDEXES=( 1 10 )
90 90
91 n-list can automatically colorize entries according to a Zsh pattern. 91 n-list can automatically colorize entries according to a Zsh pattern.
92 Following example will colorize all numbers with blue: 92 Following example will colorize all numbers with blue:
93 93
94 local NLIST_COLORING_PATTERN="[0-9]##" 94 local NLIST_COLORING_PATTERN="[0-9]##"
95 local NLIST_COLORING_COLOR=$'\x1b[00;34m' 95 local NLIST_COLORING_COLOR=$'\x1b[00;34m'
96 local NLIST_COLORING_END_COLOR=$'\x1b[0m' 96 local NLIST_COLORING_END_COLOR=$'\x1b[0m'
97 local NLIST_COLORING_MATCH_MULTIPLE=1 97 local NLIST_COLORING_MATCH_MULTIPLE=1
98 n-list "This is a number 123" "This line too has a number: 456" 98 n-list "This is a number 123" "This line too has a number: 456"
99 99
100 Blue is the default color, it doesn't have to be set. See zshexpn man page 100 Blue is the default color, it doesn't have to be set. See zshexpn man page
101 for more information on Zsh patterns. Briefly, comparing to regular 101 for more information on Zsh patterns. Briefly, comparing to regular
102 expressions, (#s) is ^, (#e) is $, # is *, ## is +. Alternative 102 expressions, (#s) is ^, (#e) is $, # is *, ## is +. Alternative
103 will work when in parenthesis, i.e. (a|b). BTW by using this method you can 103 will work when in parenthesis, i.e. (a|b). BTW by using this method you can
104 colorize output of the tools, via their config files (check out e.g. n-cd.conf, 104 colorize output of the tools, via their config files (check out e.g. n-cd.conf,
105 it uses this). 105 it uses this).
106 106
107 ## Performance 107 ## Performance
108 ZNT are fastest with Zsh before 5.0.6 and starting from 5.2 108 ZNT are fastest with Zsh before 5.0.6 and starting from 5.2
109 109
110 110
111 vim:filetype=conf 111 vim:filetype=conf
112 112
repos/robbyrussell/oh-my-zsh/plugins/zsh-navigation-tools/n-history
1 # Copy this file into /usr/share/zsh/site-functions/ 1 # Copy this file into /usr/share/zsh/site-functions/
2 # and add 'autoload n-history` to .zshrc 2 # and add 'autoload n-history` to .zshrc
3 # 3 #
4 # This function allows to browse Z shell's history and use the 4 # This function allows to browse Z shell's history and use the
5 # entries 5 # entries
6 # 6 #
7 # Uses n-list 7 # Uses n-list
8 8
9 emulate -L zsh 9 emulate -L zsh
10 10
11 setopt extendedglob 11 setopt extendedglob
12 zmodload zsh/curses 12 zmodload zsh/curses
13 zmodload zsh/parameter 13 zmodload zsh/parameter
14 14
15 local IFS=" 15 local IFS="
16 " 16 "
17 17
18 unset NLIST_COLORING_PATTERN 18 unset NLIST_COLORING_PATTERN
19 19
20 [ -f ~/.config/znt/n-list.conf ] && . ~/.config/znt/n-list.conf 20 [ -f ~/.config/znt/n-list.conf ] && . ~/.config/znt/n-list.conf
21 [ -f ~/.config/znt/n-history.conf ] && . ~/.config/znt/n-history.conf 21 [ -f ~/.config/znt/n-history.conf ] && . ~/.config/znt/n-history.conf
22 22
23 local list 23 local list
24 local selected 24 local selected
25 25
26 NLIST_REMEMBER_STATE=0 26 NLIST_REMEMBER_STATE=0
27 27
28 list=( "$history[@]" ) 28 list=( "$history[@]" )
29 list=( "${(@M)list:#(#i)*$1*}" ) 29 list=( "${(@M)list:#(#i)*$1*}" )
30 30
31 if [ "$#list" -eq 0 ]; then 31 if [ "$#list" -eq 0 ]; then
32 echo "No matching history entries" 32 echo "No matching history entries"
33 return 1 33 return 1
34 fi 34 fi
35 35
36 local NLIST_GREP_STRING="$1" 36 local NLIST_GREP_STRING="$1"
37 local NLIST_REPLACE_NEWLINES="1" 37 local NLIST_REPLACE_NEWLINES="1"
38 n-list "${list[@]}" 38 n-list "${list[@]}"
39 39
40 if [ "$REPLY" -gt 0 ]; then 40 if [ "$REPLY" -gt 0 ]; then
41 selected="$reply[REPLY]" 41 selected="$reply[REPLY]"
42 # ZLE? 42 # ZLE?
43 if [ "${(t)CURSOR}" = "integer-local-special" ]; then 43 if [ "${(t)CURSOR}" = "integer-local-special" ]; then
44 zle redisplay 44 zle redisplay
45 zle kill-whole-line 45 zle kill-buffer
46 zle -U "$selected" 46 zle -U "$selected"
47 else 47 else
48 print -zr "$selected" 48 print -zr "$selected"
49 fi 49 fi
50 else 50 else
51 [ "${(t)CURSOR}" = "integer-local-special" ] && zle redisplay 51 [ "${(t)CURSOR}" = "integer-local-special" ] && zle redisplay
52 fi 52 fi
53 53
54 # vim: set filetype=zsh: 54 # vim: set filetype=zsh:
55 55
repos/robbyrussell/oh-my-zsh/plugins/zsh-navigation-tools/n-list
1 # $1, $2, ... - elements of the list 1 # $1, $2, ... - elements of the list
2 # $NLIST_NONSELECTABLE_ELEMENTS - array of indexes (1-based) that cannot be selected 2 # $NLIST_NONSELECTABLE_ELEMENTS - array of indexes (1-based) that cannot be selected
3 # $REPLY is the output variable - contains index (1-based) or -1 when no selection 3 # $REPLY is the output variable - contains index (1-based) or -1 when no selection
4 # $reply (array) is the second part of the output - use the index (REPLY) to get selected element
4 # 5 #
5 # Copy this file into /usr/share/zsh/site-functions/ 6 # Copy this file into /usr/share/zsh/site-functions/
6 # and add 'autoload n-list` to .zshrc 7 # and add 'autoload n-list` to .zshrc
7 # 8 #
8 # This function outputs a list of elements that can be 9 # This function outputs a list of elements that can be
9 # navigated with keyboard. Uses curses library 10 # navigated with keyboard. Uses curses library
10 11
11 emulate -LR zsh 12 emulate -LR zsh
12 13
13 setopt typesetsilent extendedglob noshortloops 14 setopt typesetsilent extendedglob noshortloops
14 15
15 _nlist_has_terminfo=0 16 _nlist_has_terminfo=0
16 17
17 zmodload zsh/curses 18 zmodload zsh/curses
18 zmodload zsh/terminfo 2>/dev/null && _nlist_has_terminfo=1 19 zmodload zsh/terminfo 2>/dev/null && _nlist_has_terminfo=1
19 20
20 trap "REPLY=-2; reply=(); return" TERM INT QUIT 21 trap "REPLY=-2; reply=(); return" TERM INT QUIT
21 trap "_nlist_exit" EXIT 22 trap "_nlist_exit" EXIT
22 23
23 # Drawing and input 24 # Drawing and input
24 autoload n-list-draw n-list-input 25 autoload n-list-draw n-list-input
25 26
26 # Cleanup before any exit 27 # Cleanup before any exit
27 _nlist_exit() { 28 _nlist_exit() {
28 setopt localoptions 29 setopt localoptions
29 setopt extendedglob 30 setopt extendedglob
30 31
31 [[ "$REPLY" = -(#c0,1)[0-9]## ]] || REPLY="-1" 32 [[ "$REPLY" = -(#c0,1)[0-9]## ]] || REPLY="-1"
32 zcurses 2>/dev/null delwin inner 33 zcurses 2>/dev/null delwin inner
33 zcurses 2>/dev/null delwin main 34 zcurses 2>/dev/null delwin main
34 zcurses 2>/dev/null refresh 35 zcurses 2>/dev/null refresh
35 zcurses end 36 zcurses end
36 _nlist_alternate_screen 0 37 _nlist_alternate_screen 0
37 _nlist_cursor_visibility 1 38 _nlist_cursor_visibility 1
38 unset _nlist_has_terminfo 39 unset _nlist_has_terminfo
39 } 40 }
40 41
41 # Outputs a message in the bottom of the screen 42 # Outputs a message in the bottom of the screen
42 _nlist_status_msg() { 43 _nlist_status_msg() {
43 # -1 for border, -1 for 0-based indexing 44 # -1 for border, -1 for 0-based indexing
44 zcurses move main $(( term_height - 1 - 1 )) 2 45 zcurses move main $(( term_height - 1 - 1 )) 2
45 zcurses clear main eol 46 zcurses clear main eol
46 zcurses string main "$1" 47 zcurses string main "$1"
47 #status_msg_strlen is localized in caller 48 #status_msg_strlen is localized in caller
48 status_msg_strlen=$#1 49 status_msg_strlen=$#1
49 } 50 }
50 51
51 # Prefer tput, then module terminfo 52 # Prefer tput, then module terminfo
52 _nlist_cursor_visibility() { 53 _nlist_cursor_visibility() {
53 if type tput 2>/dev/null 1>&2; then 54 if type tput 2>/dev/null 1>&2; then
54 [ "$1" = "1" ] && { tput cvvis; tput cnorm } 55 [ "$1" = "1" ] && { tput cvvis; tput cnorm }
55 [ "$1" = "0" ] && tput civis 56 [ "$1" = "0" ] && tput civis
56 elif [ "$_nlist_has_terminfo" = "1" ]; then 57 elif [ "$_nlist_has_terminfo" = "1" ]; then
57 [ "$1" = "1" ] && { [ -n $terminfo[cvvis] ] && echo -n $terminfo[cvvis]; 58 [ "$1" = "1" ] && { [ -n $terminfo[cvvis] ] && echo -n $terminfo[cvvis];
58 [ -n $terminfo[cnorm] ] && echo -n $terminfo[cnorm] } 59 [ -n $terminfo[cnorm] ] && echo -n $terminfo[cnorm] }
59 [ "$1" = "0" ] && [ -n $terminfo[civis] ] && echo -n $terminfo[civis] 60 [ "$1" = "0" ] && [ -n $terminfo[civis] ] && echo -n $terminfo[civis]
60 fi 61 fi
61 } 62 }
62 63
63 # Reason for this function is that on some systems 64 # Reason for this function is that on some systems
64 # smcup and rmcup are not knowing why left empty 65 # smcup and rmcup are not knowing why left empty
65 _nlist_alternate_screen() { 66 _nlist_alternate_screen() {
66 [ "$_nlist_has_terminfo" -ne "1" ] && return 67 [ "$_nlist_has_terminfo" -ne "1" ] && return
67 [[ "$1" = "1" && -n "$terminfo[smcup]" ]] && return 68 [[ "$1" = "1" && -n "$terminfo[smcup]" ]] && return
68 [[ "$1" = "0" && -n "$terminfo[rmcup]" ]] && return 69 [[ "$1" = "0" && -n "$terminfo[rmcup]" ]] && return
69 70
70 case "$TERM" in 71 case "$TERM" in
71 *rxvt*) 72 *rxvt*)
72 [ "$1" = "1" ] && echo -n $'\x1b7\x1b[?47h' 73 [ "$1" = "1" ] && echo -n $'\x1b7\x1b[?47h'
73 [ "$1" = "0" ] && echo -n $'\x1b[2J\x1b[?47l\x1b8' 74 [ "$1" = "0" ] && echo -n $'\x1b[2J\x1b[?47l\x1b8'
74 ;; 75 ;;
75 *) 76 *)
76 [ "$1" = "1" ] && echo -n $'\x1b[?1049h' 77 [ "$1" = "1" ] && echo -n $'\x1b[?1049h'
77 [ "$1" = "0" ] && echo -n $'\x1b[?1049l' 78 [ "$1" = "0" ] && echo -n $'\x1b[?1049l'
78 # just to remember two other that work: $'\x1b7\x1b[r\x1b[?47h', $'\x1b[?47l\x1b8' 79 # just to remember two other that work: $'\x1b7\x1b[r\x1b[?47h', $'\x1b[?47l\x1b8'
79 ;; 80 ;;
80 esac 81 esac
81 } 82 }
82 83
83 _nlist_compute_user_vars_difference() { 84 _nlist_compute_user_vars_difference() {
84 if [[ "${(t)NLIST_NONSELECTABLE_ELEMENTS}" != "array" && 85 if [[ "${(t)NLIST_NONSELECTABLE_ELEMENTS}" != "array" &&
85 "${(t)NLIST_NONSELECTABLE_ELEMENTS}" != "array-local" ]] 86 "${(t)NLIST_NONSELECTABLE_ELEMENTS}" != "array-local" ]]
86 then 87 then
87 last_element_difference=0 88 last_element_difference=0
88 current_difference=0 89 current_difference=0
89 else 90 else
90 last_element_difference=$#NLIST_NONSELECTABLE_ELEMENTS 91 last_element_difference=$#NLIST_NONSELECTABLE_ELEMENTS
91 current_difference=0 92 current_difference=0
92 local idx 93 local idx
93 for idx in "${(n)NLIST_NONSELECTABLE_ELEMENTS[@]}"; do 94 for idx in "${(n)NLIST_NONSELECTABLE_ELEMENTS[@]}"; do
94 [ "$idx" -le "$NLIST_CURRENT_IDX" ] && current_difference+=1 || break 95 [ "$idx" -le "$NLIST_CURRENT_IDX" ] && current_difference+=1 || break
95 done 96 done
96 fi 97 fi
97 } 98 }
98 99
99 # List was processed, check if variables aren't off range 100 # List was processed, check if variables aren't off range
100 _nlist_verify_vars() { 101 _nlist_verify_vars() {
101 [ "$NLIST_CURRENT_IDX" -gt "$last_element" ] && NLIST_CURRENT_IDX="$last_element" 102 [ "$NLIST_CURRENT_IDX" -gt "$last_element" ] && NLIST_CURRENT_IDX="$last_element"
102 [[ "$NLIST_CURRENT_IDX" -eq 0 && "$last_element" -ne 0 ]] && NLIST_CURRENT_IDX=1 103 [[ "$NLIST_CURRENT_IDX" -eq 0 && "$last_element" -ne 0 ]] && NLIST_CURRENT_IDX=1
103 (( NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN=0+((NLIST_CURRENT_IDX-1)/page_height)*page_height+1 )) 104 (( NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN=0+((NLIST_CURRENT_IDX-1)/page_height)*page_height+1 ))
104 } 105 }
105 106
106 # Compute the variables which are shown to the user 107 # Compute the variables which are shown to the user
107 _nlist_setup_user_vars() { 108 _nlist_setup_user_vars() {
108 if [ "$1" = "1" ]; then 109 if [ "$1" = "1" ]; then
109 # Basic values when there are no non-selectables 110 # Basic values when there are no non-selectables
110 NLIST_USER_CURRENT_IDX="$NLIST_CURRENT_IDX" 111 NLIST_USER_CURRENT_IDX="$NLIST_CURRENT_IDX"
111 NLIST_USER_LAST_ELEMENT="$last_element" 112 NLIST_USER_LAST_ELEMENT="$last_element"
112 else 113 else
113 _nlist_compute_user_vars_difference 114 _nlist_compute_user_vars_difference
114 NLIST_USER_CURRENT_IDX=$(( NLIST_CURRENT_IDX - current_difference )) 115 NLIST_USER_CURRENT_IDX=$(( NLIST_CURRENT_IDX - current_difference ))
115 NLIST_USER_LAST_ELEMENT=$(( last_element - last_element_difference )) 116 NLIST_USER_LAST_ELEMENT=$(( last_element - last_element_difference ))
116 fi 117 fi
117 } 118 }
118 119
119 _nlist_colorify_disp_list() { 120 _nlist_colorify_disp_list() {
120 local col=$'\x1b[00;34m' reset=$'\x1b[0m' 121 local col=$'\x1b[00;34m' reset=$'\x1b[0m'
121 [ -n "$NLIST_COLORING_COLOR" ] && col="$NLIST_COLORING_COLOR" 122 [ -n "$NLIST_COLORING_COLOR" ] && col="$NLIST_COLORING_COLOR"
122 [ -n "$NLIST_COLORING_END_COLOR" ] && reset="$NLIST_COLORING_END_COLOR" 123 [ -n "$NLIST_COLORING_END_COLOR" ] && reset="$NLIST_COLORING_END_COLOR"
123 124
124 if [ "$NLIST_COLORING_MATCH_MULTIPLE" -eq 1 ]; then 125 if [ "$NLIST_COLORING_MATCH_MULTIPLE" -eq 1 ]; then
125 disp_list=( "${(@)disp_list//(#mi)$~NLIST_COLORING_PATTERN/$col${MATCH}$reset}" ) 126 disp_list=( "${(@)disp_list//(#mi)$~NLIST_COLORING_PATTERN/$col${MATCH}$reset}" )
126 else 127 else
127 disp_list=( "${(@)disp_list/(#mi)$~NLIST_COLORING_PATTERN/$col${MATCH}$reset}" ) 128 disp_list=( "${(@)disp_list/(#mi)$~NLIST_COLORING_PATTERN/$col${MATCH}$reset}" )
128 fi 129 fi
129 } 130 }
130 131
131 # 132 #
132 # Main code 133 # Main code
133 # 134 #
134 135
135 # Check if there is proper input 136 # Check if there is proper input
136 if [ "$#" -lt 1 ]; then 137 if [ "$#" -lt 1 ]; then
137 echo "Usage: n-list element_1 ..." 138 echo "Usage: n-list element_1 ..."
138 return 1 139 return 1
139 fi 140 fi
140 141
141 REPLY="-1" 142 REPLY="-1"
142 typeset -ga reply 143 typeset -ga reply
143 reply=() 144 reply=()
144 145
145 integer term_height="$LINES" 146 integer term_height="$LINES"
146 integer term_width="$COLUMNS" 147 integer term_width="$COLUMNS"
147 if [[ "$term_height" -lt 1 || "$term_width" -lt 1 ]]; then 148 if [[ "$term_height" -lt 1 || "$term_width" -lt 1 ]]; then
148 local stty_out=$( stty size ) 149 local stty_out=$( stty size )
149 term_height="${stty_out% *}" 150 term_height="${stty_out% *}"
150 term_width="${stty_out#* }" 151 term_width="${stty_out#* }"
151 fi 152 fi
152 integer inner_height=term_height-3 153 integer inner_height=term_height-3
153 integer inner_width=term_width-3 154 integer inner_width=term_width-3
154 integer page_height=inner_height 155 integer page_height=inner_height
155 integer page_width=inner_width 156 integer page_width=inner_width
156 157
157 typeset -a list disp_list 158 typeset -a list disp_list
158 integer last_element=$# 159 integer last_element=$#
159 local action 160 local action
160 local final_key 161 local final_key
161 integer selection 162 integer selection
162 integer last_element_difference=0 163 integer last_element_difference=0
163 integer current_difference=0 164 integer current_difference=0
164 local prev_search_buffer="" 165 local prev_search_buffer=""
165 integer prev_uniq_mode=0 166 integer prev_uniq_mode=0
166 integer prev_start_idx=-1 167 integer prev_start_idx=-1
168 local MBEGIN MEND MATCH mbegin mend match
167 169
168 # Ability to remember the list between calls 170 # Ability to remember the list between calls
169 if [[ -z "$NLIST_REMEMBER_STATE" || "$NLIST_REMEMBER_STATE" -eq 0 || "$NLIST_REMEMBER_STATE" -eq 2 ]]; then 171 if [[ -z "$NLIST_REMEMBER_STATE" || "$NLIST_REMEMBER_STATE" -eq 0 || "$NLIST_REMEMBER_STATE" -eq 2 ]]; then
170 NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN=1 172 NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN=1
171 NLIST_CURRENT_IDX=1 173 NLIST_CURRENT_IDX=1
172 NLIST_IS_SEARCH_MODE=0 174 NLIST_IS_SEARCH_MODE=0
173 NLIST_SEARCH_BUFFER="" 175 NLIST_SEARCH_BUFFER=""
174 NLIST_TEXT_OFFSET=0 176 NLIST_TEXT_OFFSET=0
175 NLIST_IS_UNIQ_MODE=0 177 NLIST_IS_UNIQ_MODE=0
176 178
177 # Zero - because it isn't known, unless we 179 # Zero - because it isn't known, unless we
178 # confirm that first element is selectable 180 # confirm that first element is selectable
179 NLIST_USER_CURRENT_IDX=0 181 NLIST_USER_CURRENT_IDX=0
180 [[ ${NLIST_NONSELECTABLE_ELEMENTS[(r)1]} != 1 ]] && NLIST_USER_CURRENT_IDX=1 182 [[ ${NLIST_NONSELECTABLE_ELEMENTS[(r)1]} != 1 ]] && NLIST_USER_CURRENT_IDX=1
181 NLIST_USER_LAST_ELEMENT=$(( last_element - $#NLIST_NONSELECTABLE_ELEMENTS )) 183 NLIST_USER_LAST_ELEMENT=$(( last_element - $#NLIST_NONSELECTABLE_ELEMENTS ))
182 184
183 # 2 is init once, then remember 185 # 2 is init once, then remember
184 [ "$NLIST_REMEMBER_STATE" -eq 2 ] && NLIST_REMEMBER_STATE=1 186 [ "$NLIST_REMEMBER_STATE" -eq 2 ] && NLIST_REMEMBER_STATE=1
185 fi 187 fi
186 188
187 if [ "$NLIST_START_IN_SEARCH_MODE" -eq 1 ]; then 189 if [ "$NLIST_START_IN_SEARCH_MODE" -eq 1 ]; then
188 NLIST_START_IN_SEARCH_MODE=0 190 NLIST_START_IN_SEARCH_MODE=0
189 NLIST_IS_SEARCH_MODE=1 191 NLIST_IS_SEARCH_MODE=1
190 fi 192 fi
191 193
192 if [ -n "$NLIST_SET_SEARCH_TO" ]; then 194 if [ -n "$NLIST_SET_SEARCH_TO" ]; then
193 NLIST_SEARCH_BUFFER="$NLIST_SET_SEARCH_TO" 195 NLIST_SEARCH_BUFFER="$NLIST_SET_SEARCH_TO"
194 NLIST_SET_SEARCH_TO="" 196 NLIST_SET_SEARCH_TO=""
195 fi 197 fi
196 198
197 if [ "$NLIST_START_IN_UNIQ_MODE" -eq 1 ]; then 199 if [ "$NLIST_START_IN_UNIQ_MODE" -eq 1 ]; then
198 NLIST_START_IN_UNIQ_MODE=0 200 NLIST_START_IN_UNIQ_MODE=0
199 NLIST_IS_UNIQ_MODE=1 201 NLIST_IS_UNIQ_MODE=1
200 fi 202 fi
201 203
202 _nlist_alternate_screen 1 204 _nlist_alternate_screen 1
203 zcurses init 205 zcurses init
204 zcurses delwin main 2>/dev/null 206 zcurses delwin main 2>/dev/null
205 zcurses delwin inner 2>/dev/null 207 zcurses delwin inner 2>/dev/null
206 zcurses addwin main "$term_height" "$term_width" 0 0 208 zcurses addwin main "$term_height" "$term_width" 0 0
207 zcurses addwin inner "$inner_height" "$inner_width" 1 2 209 zcurses addwin inner "$inner_height" "$inner_width" 1 2
208 zcurses bg main white/black 210 zcurses bg main white/black
209 zcurses bg inner white/black 211 zcurses bg inner white/black
210 if [ "$NLIST_IS_SEARCH_MODE" -ne 1 ]; then 212 if [ "$NLIST_IS_SEARCH_MODE" -ne 1 ]; then
211 _nlist_cursor_visibility 0 213 _nlist_cursor_visibility 0
212 fi 214 fi
213 215
214 # 216 #
215 # Listening for input 217 # Listening for input
216 # 218 #
217 219
218 local key keypad 220 local key keypad
219 221
220 # Clear input buffer 222 # Clear input buffer
221 zcurses timeout main 0 223 zcurses timeout main 0
222 zcurses input main key keypad 224 zcurses input main key keypad
223 zcurses timeout main -1 225 zcurses timeout main -1
224 key="" 226 key=""
225 keypad="" 227 keypad=""
226 228
227 # This loop makes script faster on some Zsh's (e.g. 5.0.8) 229 # This loop makes script faster on some Zsh's (e.g. 5.0.8)
228 repeat 1; do 230 repeat 1; do
229 list=( "$@" ) 231 list=( "$@" )
230 done 232 done
231 233
232 last_element="$#list" 234 last_element="$#list"
233 235
234 while (( 1 )); do 236 while (( 1 )); do
235 # Do searching (filtering with string) 237 # Do searching (filtering with string)
236 if [ -n "$NLIST_SEARCH_BUFFER" ]; then 238 if [ -n "$NLIST_SEARCH_BUFFER" ]; then
237 # Compute new list? 239 # Compute new list?
238 if [[ "$NLIST_SEARCH_BUFFER" != "$prev_search_buffer" || "$NLIST_IS_UNIQ_MODE" -ne "$prev_uniq_mode" ]]; then 240 if [[ "$NLIST_SEARCH_BUFFER" != "$prev_search_buffer" || "$NLIST_IS_UNIQ_MODE" -ne "$prev_uniq_mode" ]]; then
239 prev_search_buffer="$NLIST_SEARCH_BUFFER" 241 prev_search_buffer="$NLIST_SEARCH_BUFFER"
240 prev_uniq_mode="$NLIST_IS_UNIQ_MODE" 242 prev_uniq_mode="$NLIST_IS_UNIQ_MODE"
241 # regenerating list -> regenerating disp_list 243 # regenerating list -> regenerating disp_list
242 prev_start_idx=-1 244 prev_start_idx=-1
243 245
244 # Take all elements, including duplicates and non-selectables 246 # Take all elements, including duplicates and non-selectables
245 typeset +U list 247 typeset +U list
246 repeat 1; do 248 repeat 1; do
247 list=( "$@" ) 249 list=( "$@" )
248 done 250 done
249 251
250 # Remove non-selectable elements 252 # Remove non-selectable elements
251 [ "$#NLIST_NONSELECTABLE_ELEMENTS" -gt 0 ] && for i in "${(nO)NLIST_NONSELECTABLE_ELEMENTS[@]}"; do 253 [ "$#NLIST_NONSELECTABLE_ELEMENTS" -gt 0 ] && for i in "${(nO)NLIST_NONSELECTABLE_ELEMENTS[@]}"; do
252 list[$i]=() 254 list[$i]=()
253 done 255 done
254 256
255 # Remove duplicates 257 # Remove duplicates
256 [ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && typeset -U list 258 [ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && typeset -U list
257 259
258 last_element="$#list" 260 last_element="$#list"
259 261
260 # Next do the filtering 262 # Next do the filtering
261 local search_buffer="${NLIST_SEARCH_BUFFER%% ##}" 263 local search_buffer="${NLIST_SEARCH_BUFFER%% ##}"
262 search_buffer="${search_buffer## ##}" 264 search_buffer="${search_buffer## ##}"
263 search_buffer="${search_buffer//(#m)[][*?|#~^()><\\]/\\$MATCH}" 265 search_buffer="${search_buffer//(#m)[][*?|#~^()><\\]/\\$MATCH}"
264 local search_pattern="" 266 local search_pattern=""
265 local colsearch_pattern="" 267 local colsearch_pattern=""
266 if [ -n "$search_buffer" ]; then 268 if [ -n "$search_buffer" ]; then
267 # Patterns will be *foo*~^*bar* and foo|bar) 269 # Patterns will be *foo*~^*bar* and (foo|bar)
268 search_pattern="${search_buffer// ##/*~^*}" 270 search_pattern="${search_buffer// ##/*~^*}"
269 colsearch_pattern="${search_buffer// ##/|}" 271 colsearch_pattern="${search_buffer// ##/|}"
270 272
271 list=( "${(@M)list:#(#i)*$~search_pattern*}" ) 273 # The repeat will make the matching work on a fresh heap
274 repeat 1; do
275 list=( "${(@M)list:#(#i)*$~search_pattern*}" )
276 done
277
272 last_element="$#list" 278 last_element="$#list"
273 fi 279 fi
274 280
275 # Called after processing list 281 # Called after processing list
276 _nlist_verify_vars 282 _nlist_verify_vars
277 fi 283 fi
278 284
279 _nlist_setup_user_vars 1 285 _nlist_setup_user_vars 1
280 286
281 integer end_idx=$(( NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN + page_height - 1 )) 287 integer end_idx=$(( NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN + page_height - 1 ))
282 [ "$end_idx" -gt "$last_element" ] && end_idx=last_element 288 [ "$end_idx" -gt "$last_element" ] && end_idx=last_element
283 289
284 if [ "$prev_start_idx" -ne "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" ]; then 290 if [ "$prev_start_idx" -ne "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" ]; then
285 prev_start_idx="$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" 291 prev_start_idx="$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN"
286 disp_list=( "${(@)list[NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN, end_idx]}" ) 292 disp_list=( "${(@)list[NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN, end_idx]}" )
287 293
288 if [ -n "$colsearch_pattern" ]; then 294 if [ -n "$colsearch_pattern" ]; then
289 local red=$'\x1b[00;31m' reset=$'\x1b[00;00m' 295 local red=$'\x1b[00;31m' reset=$'\x1b[00;00m'
290 disp_list=( "${(@)disp_list//(#mi)($~colsearch_pattern)/$red${MATCH}$reset}" ) 296 # The repeat will make the matching work on a fresh heap
297 repeat 1; do
298 disp_list=( "${(@)disp_list//(#mi)($~colsearch_pattern)/$red${MATCH}$reset}" )
299 done
291 fi 300 fi
292 301
293 # We have display list, lets replace newlines with "\n" when needed (1/2) 302 # We have display list, lets replace newlines with "\n" when needed (1/2)
294 [ "$NLIST_REPLACE_NEWLINES" -eq 1 ] && disp_list=( "${(@)disp_list//$'\n'/\\n}" ) 303 [ "$NLIST_REPLACE_NEWLINES" -eq 1 ] && disp_list=( "${(@)disp_list//$'\n'/\\n}" )
295 fi 304 fi
296 305
297 # Output colored list 306 # Output colored list
298 n-list-draw "$(( (NLIST_CURRENT_IDX-1) % page_height + 1 ))" \ 307 n-list-draw "$(( (NLIST_CURRENT_IDX-1) % page_height + 1 ))" \
299 "$page_height" "$page_width" 0 0 "$NLIST_TEXT_OFFSET" inner \ 308 "$page_height" "$page_width" 0 0 "$NLIST_TEXT_OFFSET" inner \
300 "$disp_list[@]" 309 "$disp_list[@]"
301 else 310 else
302 # There is no search, but there was in previous loop 311 # There is no search, but there was in previous loop
303 # OR 312 # OR
304 # Uniq mode was entered or left out 313 # Uniq mode was entered or left out
305 # -> compute new list 314 # -> compute new list
306 if [[ -n "$prev_search_buffer" || "$NLIST_IS_UNIQ_MODE" -ne "$prev_uniq_mode" ]]; then 315 if [[ -n "$prev_search_buffer" || "$NLIST_IS_UNIQ_MODE" -ne "$prev_uniq_mode" ]]; then
307 prev_search_buffer="" 316 prev_search_buffer=""
308 prev_uniq_mode="$NLIST_IS_UNIQ_MODE" 317 prev_uniq_mode="$NLIST_IS_UNIQ_MODE"
309 # regenerating list -> regenerating disp_list 318 # regenerating list -> regenerating disp_list
310 prev_start_idx=-1 319 prev_start_idx=-1
311 320
312 # Take all elements, including duplicates and non-selectables 321 # Take all elements, including duplicates and non-selectables
313 typeset +U list 322 typeset +U list
314 repeat 1; do 323 repeat 1; do
315 list=( "$@" ) 324 list=( "$@" )
316 done 325 done
317 326
318 # Remove non-selectable elements only when in uniq mode 327 # Remove non-selectable elements only when in uniq mode
319 [ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && [ "$#NLIST_NONSELECTABLE_ELEMENTS" -gt 0 ] && 328 [ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && [ "$#NLIST_NONSELECTABLE_ELEMENTS" -gt 0 ] &&
320 for i in "${(nO)NLIST_NONSELECTABLE_ELEMENTS[@]}"; do 329 for i in "${(nO)NLIST_NONSELECTABLE_ELEMENTS[@]}"; do
321 list[$i]=() 330 list[$i]=()
322 done 331 done
323 332
324 # Remove duplicates when in uniq mode 333 # Remove duplicates when in uniq mode
325 [ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && typeset -U list 334 [ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && typeset -U list
326 335
327 last_element="$#list" 336 last_element="$#list"
328 # Called after processing list 337 # Called after processing list
329 _nlist_verify_vars 338 _nlist_verify_vars
330 fi 339 fi
331 340
332 # "1" - shouldn't bother with non-selectables 341 # "1" - shouldn't bother with non-selectables
333 _nlist_setup_user_vars "$NLIST_IS_UNIQ_MODE" 342 _nlist_setup_user_vars "$NLIST_IS_UNIQ_MODE"
334 343
335 integer end_idx=$(( NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN + page_height - 1 )) 344 integer end_idx=$(( NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN + page_height - 1 ))
336 [ "$end_idx" -gt "$last_element" ] && end_idx=last_element 345 [ "$end_idx" -gt "$last_element" ] && end_idx=last_element
337 346
338 if [ "$prev_start_idx" -ne "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" ]; then 347 if [ "$prev_start_idx" -ne "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" ]; then
339 prev_start_idx="$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" 348 prev_start_idx="$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN"
340 disp_list=( "${(@)list[NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN, end_idx]}" ) 349 disp_list=( "${(@)list[NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN, end_idx]}" )
341 350
342 [ -n "$NLIST_COLORING_PATTERN" ] && _nlist_colorify_disp_list 351 [ -n "$NLIST_COLORING_PATTERN" ] && _nlist_colorify_disp_list
343 352
344 # We have display list, lets replace newlines with "\n" when needed (2/2) 353 # We have display list, lets replace newlines with "\n" when needed (2/2)
345 [ "$NLIST_REPLACE_NEWLINES" -eq 1 ] && disp_list=( "${(@)disp_list//$'\n'/\\n}" ) 354 [ "$NLIST_REPLACE_NEWLINES" -eq 1 ] && disp_list=( "${(@)disp_list//$'\n'/\\n}" )
346 fi 355 fi
347 356
348 # Output the list 357 # Output the list
349 n-list-draw "$(( (NLIST_CURRENT_IDX-1) % page_height + 1 ))" \ 358 n-list-draw "$(( (NLIST_CURRENT_IDX-1) % page_height + 1 ))" \
350 "$page_height" "$page_width" 0 0 "$NLIST_TEXT_OFFSET" inner \ 359 "$page_height" "$page_width" 0 0 "$NLIST_TEXT_OFFSET" inner \
351 "$disp_list[@]" 360 "$disp_list[@]"
352 fi 361 fi
353 362
354 local status_msg_strlen 363 local status_msg_strlen
355 if [ "$NLIST_IS_SEARCH_MODE" = "1" ]; then 364 if [ "$NLIST_IS_SEARCH_MODE" = "1" ]; then
356 local _txt2="" 365 local _txt2=""
357 [ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && _txt2="[-UNIQ-] " 366 [ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && _txt2="[-UNIQ-] "
358 _nlist_status_msg "${_txt2}Filtering with: ${NLIST_SEARCH_BUFFER// /+}" 367 _nlist_status_msg "${_txt2}Filtering with: ${NLIST_SEARCH_BUFFER// /+}"
359 elif [[ ${NLIST_NONSELECTABLE_ELEMENTS[(r)$NLIST_CURRENT_IDX]} != $NLIST_CURRENT_IDX || 368 elif [[ ${NLIST_NONSELECTABLE_ELEMENTS[(r)$NLIST_CURRENT_IDX]} != $NLIST_CURRENT_IDX ||
360 -n "$NLIST_SEARCH_BUFFER" || "$NLIST_IS_UNIQ_MODE" -eq 1 ]]; then 369 -n "$NLIST_SEARCH_BUFFER" || "$NLIST_IS_UNIQ_MODE" -eq 1 ]]; then
361 local _txt="" _txt2="" 370 local _txt="" _txt2=""
362 [ -n "$NLIST_GREP_STRING" ] && _txt=" [$NLIST_GREP_STRING]" 371 [ -n "$NLIST_GREP_STRING" ] && _txt=" [$NLIST_GREP_STRING]"
363 [ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && _txt2="[-UNIQ-] " 372 [ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && _txt2="[-UNIQ-] "
364 _nlist_status_msg "${_txt2}Current #$NLIST_USER_CURRENT_IDX (of #$NLIST_USER_LAST_ELEMENT entries)$_txt" 373 _nlist_status_msg "${_txt2}Current #$NLIST_USER_CURRENT_IDX (of #$NLIST_USER_LAST_ELEMENT entries)$_txt"
365 else 374 else
366 _nlist_status_msg "" 375 _nlist_status_msg ""
367 fi 376 fi
368 377
369 zcurses border main 378 zcurses border main
370 379
371 local top_msg="${(C)ZSH_NAME} $ZSH_VERSION, shell level $SHLVL, $USER" 380 local top_msg="${(C)ZSH_NAME} $ZSH_VERSION, shell level $SHLVL, $USER"
372 zcurses move main 0 $(( term_width / 2 - $#top_msg / 2 )) 381 zcurses move main 0 $(( term_width / 2 - $#top_msg / 2 ))
373 zcurses string main $top_msg 382 zcurses string main $top_msg
374 383
375 zcurses refresh main inner 384 zcurses refresh main inner
376 zcurses move main $(( term_height - 1 - 1 )) $(( status_msg_strlen + 2 )) 385 zcurses move main $(( term_height - 1 - 1 )) $(( status_msg_strlen + 2 ))
377 386
378 # Wait for input 387 # Wait for input
379 zcurses input main key keypad 388 zcurses input main key keypad
380 389
381 # Get the special (i.e. "keypad") key or regular key 390 # Get the special (i.e. "keypad") key or regular key
382 if [ -n "$key" ]; then 391 if [ -n "$key" ]; then
383 final_key="$key" 392 final_key="$key"
384 elif [ -n "$keypad" ]; then 393 elif [ -n "$keypad" ]; then
385 final_key="$keypad" 394 final_key="$keypad"
386 else 395 else
387 _nlist_status_msg "Inproper input detected" 396 _nlist_status_msg "Inproper input detected"
388 zcurses refresh main inner 397 zcurses refresh main inner
389 fi 398 fi
390 399
391 n-list-input "$NLIST_CURRENT_IDX" "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" \ 400 n-list-input "$NLIST_CURRENT_IDX" "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" \
392 "$page_height" "$page_width" "$last_element" "$NLIST_TEXT_OFFSET" \ 401 "$page_height" "$page_width" "$last_element" "$NLIST_TEXT_OFFSET" \
393 "$final_key" "$NLIST_IS_SEARCH_MODE" "$NLIST_SEARCH_BUFFER" \ 402 "$final_key" "$NLIST_IS_SEARCH_MODE" "$NLIST_SEARCH_BUFFER" \
394 "$NLIST_IS_UNIQ_MODE" 403 "$NLIST_IS_UNIQ_MODE"
395 404
396 selection="$reply[1]" 405 selection="$reply[1]"
397 action="$reply[2]" 406 action="$reply[2]"
398 NLIST_CURRENT_IDX="$reply[3]" 407 NLIST_CURRENT_IDX="$reply[3]"
399 NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN="$reply[4]" 408 NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN="$reply[4]"
400 NLIST_TEXT_OFFSET="$reply[5]" 409 NLIST_TEXT_OFFSET="$reply[5]"
401 NLIST_IS_SEARCH_MODE="$reply[6]" 410 NLIST_IS_SEARCH_MODE="$reply[6]"
402 NLIST_SEARCH_BUFFER="$reply[7]" 411 NLIST_SEARCH_BUFFER="$reply[7]"
403 NLIST_IS_UNIQ_MODE="$reply[8]" 412 NLIST_IS_UNIQ_MODE="$reply[8]"
404 413
405 if [ "$action" = "SELECT" ]; then 414 if [ "$action" = "SELECT" ]; then
406 REPLY="$selection" 415 REPLY="$selection"
407 reply=( "$list[@]" ) 416 reply=( "$list[@]" )
408 break 417 break
409 elif [ "$action" = "QUIT" ]; then 418 elif [ "$action" = "QUIT" ]; then
410 REPLY=-1 419 REPLY=-1
411 reply=( "$list[@]" ) 420 reply=( "$list[@]" )
412 break 421 break
413 elif [ "$action" = "REDRAW" ]; then 422 elif [ "$action" = "REDRAW" ]; then
414 zcurses clear main redraw 423 zcurses clear main redraw
415 zcurses clear inner redraw 424 zcurses clear inner redraw
416 fi 425 fi
417 done 426 done
418 427
419 # vim: set filetype=zsh: 428 # vim: set filetype=zsh:
420 429
repos/robbyrussell/oh-my-zsh/plugins/zsh-navigation-tools/n-list-draw
1 # Copy this file into /usr/share/zsh/site-functions/ 1 # Copy this file into /usr/share/zsh/site-functions/
2 # and add 'autoload n-list-draw` to .zshrc 2 # and add 'autoload n-list-draw` to .zshrc
3 # 3 #
4 # This is an internal function not for direct use 4 # This is an internal function not for direct use
5 5
6 emulate -L zsh 6 emulate -L zsh
7 7
8 zmodload zsh/curses 8 zmodload zsh/curses
9 9
10 setopt typesetsilent extendedglob 10 setopt typesetsilent extendedglob
11 11
12 _nlist_print_with_ansi() { 12 _nlist_print_with_ansi() {
13 local win="$1" text="$2" out col chunk Xout 13 local win="$1" text="$2" out col chunk Xout
14 integer text_offset="$3" max_text_len="$4" text_len=0 no_match=0 nochunk_text_len to_skip_from_chunk to_chop_off_from_chunk before_len 14 integer text_offset="$3" max_text_len="$4" text_len=0 no_match=0 nochunk_text_len to_skip_from_chunk to_chop_off_from_chunk before_len
15 15
16 # 1 - non-escaped text, 2 - first number in the escaped text, with ; 16 # 1 - non-escaped text, 2 - first number in the escaped text, with ;
17 # 3 - second number, 4 - text after whole escape text 17 # 3 - second number, 4 - text after whole escape text
18 18
19 typeset -a c 19 typeset -a c
20 c=( black red green yellow blue magenta cyan white ) 20 c=( black red green yellow blue magenta cyan white )
21 21
22 while [[ -n "$text" && "$no_match" -eq 0 ]]; do 22 while [[ -n "$text" && "$no_match" -eq 0 ]]; do
23 if [[ "$text" = (#b)([^$'\x1b']#)$'\x1b'\[([0-9](#c0,2))(#B)(\;|)(#b)([0-9](#c0,2))m(*) ]]; then 23 if [[ "$text" = (#b)([^$'\x1b']#)$'\x1b'\[([0-9](#c0,2))(#B)(\;|)(#b)([0-9](#c0,2))m(*) ]]; then
24 # Text for further processing 24 # Text for further processing
25 text="$match[4]" 25 text="$match[4]"
26 # Text chunk to output now 26 # Text chunk to output now
27 out="$match[1]" 27 out="$match[1]"
28 # Save color 28 # Save color
29 col="$match[2]" 29 col="$match[2]"
30 (( match[3] >= 30 && match[3] <= 37 )) && col="$match[3]" 30 (( match[3] >= 30 && match[3] <= 37 )) && col="$match[3]"
31 else 31 else
32 out="$text" 32 out="$text"
33 no_match=1 33 no_match=1
34 fi 34 fi
35 35
36 if [ -n "$out" ]; then 36 if [ -n "$out" ]; then
37 ################ Expand tabs ################ 37 ################ Expand tabs ################
38 chunk="$out" 38 chunk="$out"
39 before_len="$text_len" 39 before_len="$text_len"
40 Xout="" 40 Xout=""
41 41
42 while [ -n "$chunk" ]; do 42 while [ -n "$chunk" ]; do
43 [[ "$chunk" = (#b)([^$'\t']#)$'\t'(*) ]] && { 43 [[ "$chunk" = (#b)([^$'\t']#)$'\t'(*) ]] && {
44 (( all_text_len=((before_len+${#match[1]})/8+1)*8 )) 44 (( all_text_len=((before_len+${#match[1]})/8+1)*8 ))
45 45
46 Xout+="${(r:all_text_len-before_len:: :)match[1]}" 46 Xout+="${(r:all_text_len-before_len:: :)match[1]}"
47 47
48 before_len+=all_text_len-before_len 48 before_len+=all_text_len-before_len
49 chunk="$match[2]" 49 chunk="$match[2]"
50 } || { 50 } || {
51 Xout+="$chunk" 51 Xout+="$chunk"
52 break 52 break
53 } 53 }
54 done 54 done
55 ############################################# 55 #############################################
56 56
57 # Input text length without the current chunk 57 # Input text length without the current chunk
58 nochunk_text_len=text_len 58 nochunk_text_len=text_len
59 # Input text length up to current chunk 59 # Input text length up to current chunk
60 text_len+="$#Xout" 60 text_len+="$#Xout"
61 61
62 # Should start displaying with this chunk? 62 # Should start displaying with this chunk?
63 # I.e. stop skipping left part of the input text? 63 # I.e. stop skipping left part of the input text?
64 if (( text_len > text_offset )); then 64 if (( text_len > text_offset )); then
65 to_skip_from_chunk=text_offset-nochunk_text_len 65 to_skip_from_chunk=text_offset-nochunk_text_len
66 66
67 # LEFT - is chunk off the left skip boundary? +1 for 1-based index in string 67 # LEFT - is chunk off the left skip boundary? +1 for 1-based index in string
68 (( to_skip_from_chunk > 0 )) && Xout="${Xout[to_skip_from_chunk+1,-1]}" 68 (( to_skip_from_chunk > 0 )) && Xout="${Xout[to_skip_from_chunk+1,-1]}"
69 69
70 # RIGHT - is text off the screen? 70 # RIGHT - is text off the screen?
71 if (( text_len-text_offset > max_text_len )); then 71 if (( text_len-text_offset > max_text_len )); then
72 to_chop_off_from_chunk=0+(text_len-text_offset)-max_text_len 72 to_chop_off_from_chunk=0+(text_len-text_offset)-max_text_len
73 Xout="${Xout[1,-to_chop_off_from_chunk-1]}" 73 Xout="${Xout[1,-to_chop_off_from_chunk-1]}"
74 fi 74 fi
75 75
76 [ -n "$Xout" ] && zcurses string "$win" "$Xout" 76 [ -n "$Xout" ] && zcurses string "$win" "$Xout"
77 fi 77 fi
78 fi 78 fi
79 79
80 if (( no_match == 0 )); then 80 if (( no_match == 0 )); then
81 if (( col >= 30 && col <= 37 )); then 81 if (( col >= 30 && col <= 37 )); then
82 zcurses attr "$win" $c[col-29]/black 82 zcurses attr "$win" $c[col-29]/black
83 elif [[ "$col" -eq 0 ]]; then 83 elif [[ "$col" -eq 0 ]]; then
84 zcurses attr "$win" white/black 84 zcurses attr "$win" white/black
85 fi 85 fi
86 fi 86 fi
87 done 87 done
88 } 88 }
89 89
90 integer highlight="$1" 90 integer highlight="$1"
91 integer page_height="$2" 91 integer page_height="$2"
92 integer page_width="$3" 92 integer page_width="$3"
93 local y_offset="$4" 93 local y_offset="$4"
94 local x_offset="$5" 94 local x_offset="$5"
95 local text_offset="$6" 95 local text_offset="$6"
96 local win="$7" 96 local win="$7"
97 shift 7 97 shift 7
98 integer max_text_len=page_width-x_offset 98 integer max_text_len=page_width-x_offset
99 99
100 [ "$bold" = "0" ] && bold="" || bold="+bold" 100 [ "$bold" = "0" ] && bold="" || bold="+bold"
101 [[ "$active_text" = "underline" || "$active_text" = "reverse" ]] || active_text="reverse" 101 [[ "$active_text" = "underline" || "$active_text" = "reverse" ]] || local active_text="reverse"
102 # With Linux terminal underline won't work properly 102 # With Linux terminal underline won't work properly
103 [ "$TERM" = "linux" ] && active_text="reverse" 103 [ "$TERM" = "linux" ] && active_text="reverse"
104 104
105 integer max_idx=page_height 105 integer max_idx=page_height
106 integer end_idx=max_idx 106 integer end_idx=max_idx
107 [ "$end_idx" -gt "$#" ] && end_idx="$#" 107 [ "$end_idx" -gt "$#" ] && end_idx="$#"
108 integer y=y_offset 108 integer y=y_offset
109 109
110 zcurses attr "$win" $bold white/black 110 zcurses attr "$win" $bold white/black
111 111
112 integer i text_len 112 integer i text_len
113 local text 113 local text
114 for (( i=1; i<=end_idx; i++ )); do 114 for (( i=1; i<=end_idx; i++ )); do
115 zcurses move "$win" $y "$x_offset" 115 zcurses move "$win" $y "$x_offset"
116 116
117 [ "$i" = "$highlight" ] && zcurses attr "$win" +"$active_text" 117 [ "$i" = "$highlight" ] && zcurses attr "$win" +"$active_text"
118 _nlist_print_with_ansi "$win" "$@[i]" "$text_offset" "$max_text_len" 118 _nlist_print_with_ansi "$win" "$@[i]" "$text_offset" "$max_text_len"
119 zcurses clear "$win" eol 119 zcurses clear "$win" eol
120 [ "$i" = "$highlight" ] && zcurses attr "$win" -"$active_text" 120 [ "$i" = "$highlight" ] && zcurses attr "$win" -"$active_text"
121 121
122 y+=1 122 y+=1
123 done 123 done
124 124
125 if [ "$end_idx" -lt "$max_idx" ]; then 125 if [ "$end_idx" -lt "$max_idx" ]; then
126 zcurses move "$win" $y "$x_offset" 126 zcurses move "$win" $y "$x_offset"
127 zcurses clear "$win" eol 127 zcurses clear "$win" eol
128 fi 128 fi
129 129
130 zcurses attr "$win" white/black 130 zcurses attr "$win" white/black
131 # vim: set filetype=zsh: 131 # vim: set filetype=zsh:
132 132
repos/robbyrussell/oh-my-zsh/plugins/zsh-navigation-tools/n-list-input
1 # Copy this file into /usr/share/zsh/site-functions/ 1 # Copy this file into /usr/share/zsh/site-functions/
2 # and add 'autoload n-list-input` to .zshrc 2 # and add 'autoload n-list-input` to .zshrc
3 # 3 #
4 # This is an internal function not for direct use 4 # This is an internal function not for direct use
5 5
6 emulate -L zsh 6 emulate -L zsh
7 7
8 zmodload zsh/curses 8 zmodload zsh/curses
9 9
10 setopt typesetsilent 10 setopt typesetsilent
11 11
12 # Compute first to show index 12 # Compute first to show index
13 _nlist_compute_first_to_show_idx() { 13 _nlist_compute_first_to_show_idx() {
14 from_what_idx_list_is_shown=0+((current_idx-1)/page_height)*page_height+1 14 from_what_idx_list_is_shown=0+((current_idx-1)/page_height)*page_height+1
15 } 15 }
16 16
17 typeset -ga reply 17 typeset -ga reply
18 reply=( -1 '' ) 18 reply=( -1 '' )
19 integer current_idx="$1" 19 integer current_idx="$1"
20 integer from_what_idx_list_is_shown="$2" 20 integer from_what_idx_list_is_shown="$2"
21 integer page_height="$3" 21 integer page_height="$3"
22 integer page_width="$4" 22 integer page_width="$4"
23 integer last_element="$5" 23 integer last_element="$5"
24 integer hscroll="$6" 24 integer hscroll="$6"
25 local key="$7" 25 local key="$7"
26 integer search="$8" 26 integer search="$8"
27 local buffer="$9" 27 local buffer="$9"
28 integer uniq_mode="$10" 28 integer uniq_mode="$10"
29 29
30 # 30 #
31 # Listening for input 31 # Listening for input
32 # 32 #
33 33
34 if [ "$search" = "0" ]; then 34 if [ "$search" = "0" ]; then
35 35
36 case "$key" in 36 case "$key" in
37 (UP|k|$'\C-P') 37 (UP|k|$'\C-P')
38 # Are there any elements before the current one? 38 # Are there any elements before the current one?
39 [ "$current_idx" -gt 1 ] && current_idx=current_idx-1; 39 [ "$current_idx" -gt 1 ] && current_idx=current_idx-1;
40 _nlist_compute_first_to_show_idx 40 _nlist_compute_first_to_show_idx
41 ;; 41 ;;
42 (DOWN|j|$'\C-N') 42 (DOWN|j|$'\C-N')
43 # Are there any elements after the current one? 43 # Are there any elements after the current one?
44 [ "$current_idx" -lt "$last_element" ] && current_idx=current_idx+1; 44 [ "$current_idx" -lt "$last_element" ] && current_idx=current_idx+1;
45 _nlist_compute_first_to_show_idx 45 _nlist_compute_first_to_show_idx
46 ;; 46 ;;
47 (PPAGE) 47 (PPAGE|$'\b'|$'\C-?'|BACKSPACE)
48 current_idx=current_idx-page_height 48 current_idx=current_idx-page_height
49 [ "$current_idx" -lt 1 ] && current_idx=1; 49 [ "$current_idx" -lt 1 ] && current_idx=1;
50 _nlist_compute_first_to_show_idx 50 _nlist_compute_first_to_show_idx
51 ;; 51 ;;
52 (NPAGE|" ") 52 (NPAGE|" ")
53 current_idx=current_idx+page_height 53 current_idx=current_idx+page_height
54 [ "$current_idx" -gt "$last_element" ] && current_idx=last_element; 54 [ "$current_idx" -gt "$last_element" ] && current_idx=last_element;
55 _nlist_compute_first_to_show_idx 55 _nlist_compute_first_to_show_idx
56 ;; 56 ;;
57 ($'\C-U') 57 ($'\C-U')
58 current_idx=current_idx-page_height/2 58 current_idx=current_idx-page_height/2
59 [ "$current_idx" -lt 1 ] && current_idx=1; 59 [ "$current_idx" -lt 1 ] && current_idx=1;
60 _nlist_compute_first_to_show_idx 60 _nlist_compute_first_to_show_idx
61 ;; 61 ;;
62 ($'\C-D') 62 ($'\C-D')
63 current_idx=current_idx+page_height/2 63 current_idx=current_idx+page_height/2
64 [ "$current_idx" -gt "$last_element" ] && current_idx=last_element; 64 [ "$current_idx" -gt "$last_element" ] && current_idx=last_element;
65 _nlist_compute_first_to_show_idx 65 _nlist_compute_first_to_show_idx
66 ;; 66 ;;
67 (HOME|g) 67 (HOME|g)
68 current_idx=1 68 current_idx=1
69 _nlist_compute_first_to_show_idx 69 _nlist_compute_first_to_show_idx
70 ;; 70 ;;
71 (END|G) 71 (END|G)
72 current_idx=last_element 72 current_idx=last_element
73 _nlist_compute_first_to_show_idx 73 _nlist_compute_first_to_show_idx
74 ;; 74 ;;
75 ($'\n') 75 ($'\n'|ENTER)
76 # Is that element selectable? 76 # Is that element selectable?
77 # Check for this only when there is no search 77 # Check for this only when there is no search
78 if [[ "$NLIST_SEARCH_BUFFER" != "" || "$NLIST_IS_UNIQ_MODE" -eq 1 || 78 if [[ "$NLIST_SEARCH_BUFFER" != "" || "$NLIST_IS_UNIQ_MODE" -eq 1 ||
79 ${NLIST_NONSELECTABLE_ELEMENTS[(r)$current_idx]} != $current_idx ]] 79 ${NLIST_NONSELECTABLE_ELEMENTS[(r)$current_idx]} != $current_idx ]]
80 then 80 then
81 # Save current element in the result variable 81 # Save current element in the result variable
82 reply=( $current_idx SELECT ) 82 reply=( $current_idx SELECT )
83 fi 83 fi
84 ;; 84 ;;
85 (q) 85 (q)
86 reply=( -1 QUIT ) 86 reply=( -1 QUIT )
87 ;; 87 ;;
88 (/) 88 (/)
89 search=1 89 search=1
90 _nlist_cursor_visibility 1 90 _nlist_cursor_visibility 1
91 ;; 91 ;;
92 ($'\t') 92 ($'\t')
93 reply=( $current_idx LEAVE ) 93 reply=( $current_idx LEAVE )
94 ;; 94 ;;
95 ($'\C-L') 95 ($'\C-L')
96 reply=( -1 REDRAW ) 96 reply=( -1 REDRAW )
97 ;; 97 ;;
98 (\]) 98 (\])
99 [[ "${(t)NLIST_HOP_INDEXES}" = "array" || "${(t)NLIST_HOP_INDEXES}" = "array-local" ]] && 99 [[ "${(t)NLIST_HOP_INDEXES}" = "array" || "${(t)NLIST_HOP_INDEXES}" = "array-local" ]] &&
100 [ -z "$NLIST_SEARCH_BUFFER" ] && [ "$NLIST_IS_UNIQ_MODE" -eq 0 ] && 100 [ -z "$NLIST_SEARCH_BUFFER" ] && [ "$NLIST_IS_UNIQ_MODE" -eq 0 ] &&
101 for idx in "${(n)NLIST_HOP_INDEXES[@]}"; do 101 for idx in "${(n)NLIST_HOP_INDEXES[@]}"; do
102 if [ "$idx" -gt "$current_idx" ]; then 102 if [ "$idx" -gt "$current_idx" ]; then
103 current_idx=$idx 103 current_idx=$idx
104 _nlist_compute_first_to_show_idx 104 _nlist_compute_first_to_show_idx
105 break 105 break
106 fi 106 fi
107 done 107 done
108 ;; 108 ;;
109 (\[) 109 (\[)
110 [[ "${(t)NLIST_HOP_INDEXES}" = "array" || "${(t)NLIST_HOP_INDEXES}" = "array-local" ]] && 110 [[ "${(t)NLIST_HOP_INDEXES}" = "array" || "${(t)NLIST_HOP_INDEXES}" = "array-local" ]] &&
111 [ -z "$NLIST_SEARCH_BUFFER" ] && [ "$NLIST_IS_UNIQ_MODE" -eq 0 ] && 111 [ -z "$NLIST_SEARCH_BUFFER" ] && [ "$NLIST_IS_UNIQ_MODE" -eq 0 ] &&
112 for idx in "${(nO)NLIST_HOP_INDEXES[@]}"; do 112 for idx in "${(nO)NLIST_HOP_INDEXES[@]}"; do
113 if [ "$idx" -lt "$current_idx" ]; then 113 if [ "$idx" -lt "$current_idx" ]; then
114 current_idx=$idx 114 current_idx=$idx
115 _nlist_compute_first_to_show_idx 115 _nlist_compute_first_to_show_idx
116 break 116 break
117 fi 117 fi
118 done 118 done
119 ;; 119 ;;
120 ('<'|'{'|LEFT|'h') 120 ('<'|'{'|LEFT|'h')
121 hscroll=hscroll-7 121 hscroll=hscroll-7
122 [ "$hscroll" -lt 0 ] && hscroll=0 122 [ "$hscroll" -lt 0 ] && hscroll=0
123 ;; 123 ;;
124 ('>'|'}'|RIGHT|'l') 124 ('>'|'}'|RIGHT|'l')
125 hscroll+=7 125 hscroll+=7
126 ;; 126 ;;
127 ($'\E') 127 ($'\E')
128 buffer="" 128 buffer=""
129 ;; 129 ;;
130 (o|$'\C-O') 130 (o|$'\C-O')
131 uniq_mode=1-uniq_mode 131 uniq_mode=1-uniq_mode
132 ;; 132 ;;
133 (*) 133 (*)
134 ;; 134 ;;
135 esac 135 esac
136 136
137 else 137 else
138 138
139 case "$key" in 139 case "$key" in
140 ($'\n') 140 ($'\n'|ENTER)
141 search=0 141 search=0
142 _nlist_cursor_visibility 0 142 _nlist_cursor_visibility 0
143 ;; 143 ;;
144 ($'\C-L') 144 ($'\C-L')
145 reply=( -1 REDRAW ) 145 reply=( -1 REDRAW )
146 ;; 146 ;;
147 147
148 # 148 #
149 # Slightly limited navigation 149 # Slightly limited navigation
150 # 150 #
151 151
152 (UP|$'\C-P') 152 (UP|$'\C-P')
153 [ "$current_idx" -gt 1 ] && current_idx=current_idx-1; 153 [ "$current_idx" -gt 1 ] && current_idx=current_idx-1;
154 _nlist_compute_first_to_show_idx 154 _nlist_compute_first_to_show_idx
155 ;; 155 ;;
156 (DOWN|$'\C-N') 156 (DOWN|$'\C-N')
157 [ "$current_idx" -lt "$last_element" ] && current_idx=current_idx+1; 157 [ "$current_idx" -lt "$last_element" ] && current_idx=current_idx+1;
158 _nlist_compute_first_to_show_idx 158 _nlist_compute_first_to_show_idx
159 ;; 159 ;;
160 (PPAGE) 160 (PPAGE)
161 current_idx=current_idx-page_height 161 current_idx=current_idx-page_height
162 [ "$current_idx" -lt 1 ] && current_idx=1; 162 [ "$current_idx" -lt 1 ] && current_idx=1;
163 _nlist_compute_first_to_show_idx 163 _nlist_compute_first_to_show_idx
164 ;; 164 ;;
165 (NPAGE) 165 (NPAGE)
166 current_idx=current_idx+page_height 166 current_idx=current_idx+page_height
167 [ "$current_idx" -gt "$last_element" ] && current_idx=last_element; 167 [ "$current_idx" -gt "$last_element" ] && current_idx=last_element;
168 _nlist_compute_first_to_show_idx 168 _nlist_compute_first_to_show_idx
169 ;; 169 ;;
170 ($'\C-U') 170 ($'\C-U')
171 current_idx=current_idx-page_height/2 171 current_idx=current_idx-page_height/2
172 [ "$current_idx" -lt 1 ] && current_idx=1; 172 [ "$current_idx" -lt 1 ] && current_idx=1;
173 _nlist_compute_first_to_show_idx 173 _nlist_compute_first_to_show_idx
174 ;; 174 ;;
175 ($'\C-D') 175 ($'\C-D')
176 current_idx=current_idx+page_height/2 176 current_idx=current_idx+page_height/2
177 [ "$current_idx" -gt "$last_element" ] && current_idx=last_element; 177 [ "$current_idx" -gt "$last_element" ] && current_idx=last_element;
178 _nlist_compute_first_to_show_idx 178 _nlist_compute_first_to_show_idx
179 ;; 179 ;;
180 (HOME) 180 (HOME)
181 current_idx=1 181 current_idx=1
182 _nlist_compute_first_to_show_idx 182 _nlist_compute_first_to_show_idx
183 ;; 183 ;;
184 (END) 184 (END)
185 current_idx=last_element 185 current_idx=last_element
186 _nlist_compute_first_to_show_idx 186 _nlist_compute_first_to_show_idx
187 ;; 187 ;;
188 (LEFT) 188 (LEFT)
189 hscroll=hscroll-7 189 hscroll=hscroll-7
190 [ "$hscroll" -lt 0 ] && hscroll=0 190 [ "$hscroll" -lt 0 ] && hscroll=0
191 ;; 191 ;;
192 (RIGHT) 192 (RIGHT)
193 hscroll+=7 193 hscroll+=7
194 ;; 194 ;;
195 (F1|F2|F3|F4|F5|F6|F7|F8|F9|F10) 195 (F1|F2|F3|F4|F5|F6|F7|F8|F9|F10)
196 # ignore 196 # ignore
197 ;; 197 ;;
198 198
199 # 199 #
200 # The input 200 # The input
201 # 201 #
202 202
203 ($'\b'|$'\C-?'|BACKSPACE) 203 ($'\b'|$'\C-?'|BACKSPACE)
204 buffer="${buffer%?}" 204 buffer="${buffer%?}"
205 ;; 205 ;;
206 ($'\C-W') 206 ($'\C-W')
207 [ "$buffer" = "${buffer% *}" ] && buffer="" || buffer="${buffer% *}" 207 [ "$buffer" = "${buffer% *}" ] && buffer="" || buffer="${buffer% *}"
208 ;; 208 ;;
209 ($'\C-K') 209 ($'\C-K')
210 buffer="" 210 buffer=""
211 ;; 211 ;;
212 ($'\E') 212 ($'\E')
213 buffer="" 213 buffer=""
214 search=0 214 search=0
215 _nlist_cursor_visibility 0 215 _nlist_cursor_visibility 0
216 ;; 216 ;;
217 ($'\C-O') 217 ($'\C-O')
218 uniq_mode=1-uniq_mode 218 uniq_mode=1-uniq_mode
219 ;; 219 ;;
220 (*) 220 (*)
221 if [[ $#key == 1 && $((#key)) -lt 31 ]]; then 221 if [[ $#key == 1 && $((#key)) -lt 31 ]]; then
222 # ignore all other control keys 222 # ignore all other control keys
223 else 223 else
224 buffer+="$key" 224 buffer+="$key"
225 fi 225 fi
226 ;; 226 ;;
227 esac 227 esac
228 228
229 fi 229 fi
230 230
231 reply[3]="$current_idx" 231 reply[3]="$current_idx"
232 reply[4]="$from_what_idx_list_is_shown" 232 reply[4]="$from_what_idx_list_is_shown"
233 reply[5]="$hscroll" 233 reply[5]="$hscroll"
234 reply[6]="$search" 234 reply[6]="$search"
235 reply[7]="$buffer" 235 reply[7]="$buffer"
236 reply[8]="$uniq_mode" 236 reply[8]="$uniq_mode"
237 237
238 # vim: set filetype=zsh: 238 # vim: set filetype=zsh:
239 239
repos/robbyrussell/oh-my-zsh/plugins/zsh-navigation-tools/znt-history-widget
1 autoload znt-usetty-wrapper n-history 1 autoload znt-usetty-wrapper n-history
2 local NLIST_START_IN_SEARCH_MODE=1 2 local NLIST_START_IN_SEARCH_MODE=1
3 local NLIST_START_IN_UNIQ_MODE=1 3 local NLIST_START_IN_UNIQ_MODE=1
4 local NLIST_SET_SEARCH_TO="$BUFFER" 4
5 # Only if current $BUFFER doesn't come from history
6 if [ "$HISTCMD" = "$HISTNO" ]; then
7 local NLIST_SET_SEARCH_TO="$BUFFER"
8 fi
5 9
6 znt-usetty-wrapper n-history "$@" 10 znt-usetty-wrapper n-history "$@"
7 11
8 unset NLIST_START_IN_SEARCH_MODE 12 unset NLIST_START_IN_SEARCH_MODE
9 unset NLIST_START_IN_UNIQ_MODE 13 unset NLIST_START_IN_UNIQ_MODE
10 unset NLIST_SET_SEARCH_TO 14 unset NLIST_SET_SEARCH_TO
11 15