Commit f5c7faa5a94adfa337927b3b4cd0eb3c354bf343
1 parent
7378b55ded
Exists in
master
and in
1 other branch
Squashed 'repos/robbyrussell/oh-my-zsh/' changes from 00344f7..ee34381
ee34381 Use $HOME instead of tilde inside quotes 3841115 Merge pull request #4654 from mcornella/termsupport-cleanup c82f49e Merge pull request #4652 from psprint/master 4e30688 Cleanup update_terminalapp_cwd function eca912e Quote all variables in if statements 103eb32 Use a case structure to id terminal types d427ac1 znt: twice as fast searching ae84be7 znt: updated README.md git-subtree-dir: repos/robbyrussell/oh-my-zsh git-subtree-split: ee343814b799cc44b84d8999d5cb444159815bac
Showing 4 changed files with 39 additions and 27 deletions Inline Diff
README.markdown
1 |  | 1 |  |
2 | 2 | ||
3 | 3 | ||
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. | 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 | 5 | ||
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. | 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 | 7 | ||
8 | To learn more, visit [ohmyz.sh](http://ohmyz.sh) and/or follow [ohmyzsh](https://twitter.com/ohmyzsh) on Twitter. | 8 | To learn more, visit [ohmyz.sh](http://ohmyz.sh) and/or follow [ohmyzsh](https://twitter.com/ohmyzsh) on Twitter. |
9 | 9 | ||
10 | ## Getting Started | 10 | ## Getting Started |
11 | 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 |  | 80 |  |
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="~/.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](https://github.com/robbyrussell/oh-my-zsh/blob/master/MIT-LICENSE.txt). | 213 | Oh My Zsh is released under the [MIT license](https://github.com/robbyrussell/oh-my-zsh/blob/master/MIT-LICENSE.txt). |
214 | 214 |
lib/termsupport.zsh
1 | # Set terminal window and tab/icon title | 1 | # Set terminal window and tab/icon title |
2 | # | 2 | # |
3 | # usage: title short_tab_title [long_window_title] | 3 | # usage: title short_tab_title [long_window_title] |
4 | # | 4 | # |
5 | # See: http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1 | 5 | # See: http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1 |
6 | # Fully supports screen, iterm, and probably most modern xterm and rxvt | 6 | # Fully supports screen, iterm, and probably most modern xterm and rxvt |
7 | # (In screen, only short_tab_title is used) | 7 | # (In screen, only short_tab_title is used) |
8 | # Limited support for Apple Terminal (Terminal can't set window and tab separately) | 8 | # Limited support for Apple Terminal (Terminal can't set window and tab separately) |
9 | function title { | 9 | function title { |
10 | emulate -L zsh | 10 | emulate -L zsh |
11 | setopt prompt_subst | 11 | setopt prompt_subst |
12 | 12 | ||
13 | [[ "$EMACS" == *term* ]] && return | 13 | [[ "$EMACS" == *term* ]] && return |
14 | 14 | ||
15 | # if $2 is unset use $1 as default | 15 | # if $2 is unset use $1 as default |
16 | # if it is set and empty, leave it as is | 16 | # if it is set and empty, leave it as is |
17 | : ${2=$1} | 17 | : ${2=$1} |
18 | 18 | ||
19 | if [[ "$TERM" == screen* ]]; then | 19 | case "$TERM" in |
20 | print -Pn "\ek$1:q\e\\" #set screen hardstatus, usually truncated at 20 chars | 20 | cygwin|xterm*|putty*|rxvt*|ansi) |
21 | elif [[ "$TERM" == xterm* ]] || [[ "$TERM" == putty* ]] || [[ "$TERM" == rxvt* ]] || [[ "$TERM" == ansi ]] || [[ "$TERM" == cygwin ]] || [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then | 21 | print -Pn "\e]2;$2:q\a" # set window name |
22 | print -Pn "\e]2;$2:q\a" #set window name | 22 | print -Pn "\e]1;$1:q\a" # set tab name |
23 | print -Pn "\e]1;$1:q\a" #set icon (=tab) name | 23 | ;; |
24 | fi | 24 | screen*) |
25 | print -Pn "\ek$1:q\e\\" # set screen hardstatus | ||
26 | ;; | ||
27 | *) | ||
28 | if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then | ||
29 | print -Pn "\e]2;$2:q\a" # set window name | ||
30 | print -Pn "\e]1;$1:q\a" # set tab name | ||
31 | fi | ||
32 | ;; | ||
33 | esac | ||
25 | } | 34 | } |
26 | 35 | ||
27 | ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD | 36 | ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD |
28 | ZSH_THEME_TERM_TITLE_IDLE="%n@%m: %~" | 37 | ZSH_THEME_TERM_TITLE_IDLE="%n@%m: %~" |
29 | # Avoid duplication of directory in terminals with independent dir display | 38 | # Avoid duplication of directory in terminals with independent dir display |
30 | if [[ $TERM_PROGRAM == Apple_Terminal ]]; then | 39 | if [[ "$TERM_PROGRAM" == Apple_Terminal ]]; then |
31 | ZSH_THEME_TERM_TITLE_IDLE="%n@%m" | 40 | ZSH_THEME_TERM_TITLE_IDLE="%n@%m" |
32 | fi | 41 | fi |
33 | 42 | ||
34 | # Runs before showing the prompt | 43 | # Runs before showing the prompt |
35 | function omz_termsupport_precmd { | 44 | function omz_termsupport_precmd { |
36 | emulate -L zsh | 45 | emulate -L zsh |
37 | if [[ $DISABLE_AUTO_TITLE == true ]]; then | 46 | |
47 | if [[ "$DISABLE_AUTO_TITLE" == true ]]; then | ||
38 | return | 48 | return |
39 | fi | 49 | fi |
40 | 50 | ||
41 | title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE | 51 | title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE |
42 | } | 52 | } |
43 | 53 | ||
44 | # Runs before executing the command | 54 | # Runs before executing the command |
45 | function omz_termsupport_preexec { | 55 | function omz_termsupport_preexec { |
46 | emulate -L zsh | 56 | emulate -L zsh |
47 | if [[ $DISABLE_AUTO_TITLE == true ]]; then | 57 | setopt extended_glob |
58 | |||
59 | if [[ "$DISABLE_AUTO_TITLE" == true ]]; then | ||
48 | return | 60 | return |
49 | fi | 61 | fi |
50 | 62 | ||
51 | setopt extended_glob | ||
52 | |||
53 | # cmd name only, or if this is sudo or ssh, the next cmd | 63 | # cmd name only, or if this is sudo or ssh, the next cmd |
54 | local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%} | 64 | local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%} |
55 | local LINE="${2:gs/%/%%}" | 65 | local LINE="${2:gs/%/%%}" |
56 | 66 | ||
57 | title '$CMD' '%100>...>$LINE%<<' | 67 | title '$CMD' '%100>...>$LINE%<<' |
58 | } | 68 | } |
59 | 69 | ||
60 | precmd_functions+=(omz_termsupport_precmd) | 70 | precmd_functions+=(omz_termsupport_precmd) |
61 | preexec_functions+=(omz_termsupport_preexec) | 71 | preexec_functions+=(omz_termsupport_preexec) |
62 | 72 | ||
63 | 73 | ||
64 | # Keep Apple Terminal.app's current working directory updated | 74 | # Keep Apple Terminal.app's current working directory updated |
65 | # Based on this answer: http://superuser.com/a/315029 | 75 | # Based on this answer: http://superuser.com/a/315029 |
66 | # With extra fixes to handle multibyte chars and non-UTF-8 locales | 76 | # With extra fixes to handle multibyte chars and non-UTF-8 locales |
67 | 77 | ||
68 | if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then | 78 | if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then |
69 | |||
70 | # Emits the control sequence to notify Terminal.app of the cwd | 79 | # Emits the control sequence to notify Terminal.app of the cwd |
80 | # Identifies the directory using a file: URI scheme, including | ||
81 | # the host name to disambiguate local vs. remote paths. | ||
71 | function update_terminalapp_cwd() { | 82 | function update_terminalapp_cwd() { |
72 | emulate -L zsh | 83 | emulate -L zsh |
73 | # Identify the directory using a "file:" scheme URL, including | ||
74 | # the host name to disambiguate local vs. remote paths. | ||
75 | 84 | ||
76 | # Percent-encode the pathname. | 85 | # Percent-encode the pathname. |
77 | local URL_PATH="$(omz_urlencode -P $PWD)" | 86 | local URL_PATH="$(omz_urlencode -P $PWD)" |
78 | [[ $? != 0 ]] && return 1 | 87 | [[ $? != 0 ]] && return 1 |
79 | local PWD_URL="file://$HOST$URL_PATH" | 88 | |
80 | # Undocumented Terminal.app-specific control sequence | 89 | # Undocumented Terminal.app-specific control sequence |
81 | printf '\e]7;%s\a' $PWD_URL | 90 | printf '\e]7;%s\a' "file://$HOST$URL_PATH" |
82 | } | 91 | } |
83 | 92 | ||
84 | # Use a precmd hook instead of a chpwd hook to avoid contaminating output | 93 | # Use a precmd hook instead of a chpwd hook to avoid contaminating output |
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 "^T" 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 is fastest with Zsh before 5.0.8 and starting from 5.2 (the version yet to | 108 | ZNT are fastest with Zsh before 5.0.8 and starting from 5.2 (the version yet to |
109 | be released). | 109 | be released). |
110 | 110 | ||
111 | # vim:filetype=conf | 111 | |
112 | vim:filetype=conf | ||
112 | 113 |
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 | # | 4 | # |
5 | # Copy this file into /usr/share/zsh/site-functions/ | 5 | # Copy this file into /usr/share/zsh/site-functions/ |
6 | # and add 'autoload n-list` to .zshrc | 6 | # and add 'autoload n-list` to .zshrc |
7 | # | 7 | # |
8 | # This function outputs a list of elements that can be | 8 | # This function outputs a list of elements that can be |
9 | # navigated with keyboard. Uses curses library | 9 | # navigated with keyboard. Uses curses library |
10 | 10 | ||
11 | emulate -LR zsh | 11 | emulate -LR zsh |
12 | 12 | ||
13 | setopt typesetsilent extendedglob noshortloops | 13 | setopt typesetsilent extendedglob noshortloops |
14 | 14 | ||
15 | _nlist_has_terminfo=0 | 15 | _nlist_has_terminfo=0 |
16 | 16 | ||
17 | zmodload zsh/curses | 17 | zmodload zsh/curses |
18 | zmodload zsh/terminfo 2>/dev/null && _nlist_has_terminfo=1 | 18 | zmodload zsh/terminfo 2>/dev/null && _nlist_has_terminfo=1 |
19 | 19 | ||
20 | trap "REPLY=-2; reply=(); return" TERM INT QUIT | 20 | trap "REPLY=-2; reply=(); return" TERM INT QUIT |
21 | trap "_nlist_exit" EXIT | 21 | trap "_nlist_exit" EXIT |
22 | 22 | ||
23 | # Drawing and input | 23 | # Drawing and input |
24 | autoload n-list-draw n-list-input | 24 | autoload n-list-draw n-list-input |
25 | 25 | ||
26 | # Cleanup before any exit | 26 | # Cleanup before any exit |
27 | _nlist_exit() { | 27 | _nlist_exit() { |
28 | setopt localoptions | 28 | setopt localoptions |
29 | setopt extendedglob | 29 | setopt extendedglob |
30 | 30 | ||
31 | [[ "$REPLY" = -(#c0,1)[0-9]## ]] || REPLY="-1" | 31 | [[ "$REPLY" = -(#c0,1)[0-9]## ]] || REPLY="-1" |
32 | zcurses 2>/dev/null delwin inner | 32 | zcurses 2>/dev/null delwin inner |
33 | zcurses 2>/dev/null delwin main | 33 | zcurses 2>/dev/null delwin main |
34 | zcurses 2>/dev/null refresh | 34 | zcurses 2>/dev/null refresh |
35 | zcurses end | 35 | zcurses end |
36 | _nlist_alternate_screen 0 | 36 | _nlist_alternate_screen 0 |
37 | _nlist_cursor_visibility 1 | 37 | _nlist_cursor_visibility 1 |
38 | unset _nlist_has_terminfo | 38 | unset _nlist_has_terminfo |
39 | } | 39 | } |
40 | 40 | ||
41 | # Outputs a message in the bottom of the screen | 41 | # Outputs a message in the bottom of the screen |
42 | _nlist_status_msg() { | 42 | _nlist_status_msg() { |
43 | # -1 for border, -1 for 0-based indexing | 43 | # -1 for border, -1 for 0-based indexing |
44 | zcurses move main $(( term_height - 1 - 1 )) 2 | 44 | zcurses move main $(( term_height - 1 - 1 )) 2 |
45 | zcurses clear main eol | 45 | zcurses clear main eol |
46 | zcurses string main "$1" | 46 | zcurses string main "$1" |
47 | #status_msg_strlen is localized in caller | 47 | #status_msg_strlen is localized in caller |
48 | status_msg_strlen=$#1 | 48 | status_msg_strlen=$#1 |
49 | } | 49 | } |
50 | 50 | ||
51 | # Prefer tput, then module terminfo | 51 | # Prefer tput, then module terminfo |
52 | _nlist_cursor_visibility() { | 52 | _nlist_cursor_visibility() { |
53 | if type tput 2>/dev/null 1>&2; then | 53 | if type tput 2>/dev/null 1>&2; then |
54 | [ "$1" = "1" ] && { tput cvvis; tput cnorm } | 54 | [ "$1" = "1" ] && { tput cvvis; tput cnorm } |
55 | [ "$1" = "0" ] && tput civis | 55 | [ "$1" = "0" ] && tput civis |
56 | elif [ "$_nlist_has_terminfo" = "1" ]; then | 56 | elif [ "$_nlist_has_terminfo" = "1" ]; then |
57 | [ "$1" = "1" ] && { [ -n $terminfo[cvvis] ] && echo -n $terminfo[cvvis]; | 57 | [ "$1" = "1" ] && { [ -n $terminfo[cvvis] ] && echo -n $terminfo[cvvis]; |
58 | [ -n $terminfo[cnorm] ] && echo -n $terminfo[cnorm] } | 58 | [ -n $terminfo[cnorm] ] && echo -n $terminfo[cnorm] } |
59 | [ "$1" = "0" ] && [ -n $terminfo[civis] ] && echo -n $terminfo[civis] | 59 | [ "$1" = "0" ] && [ -n $terminfo[civis] ] && echo -n $terminfo[civis] |
60 | fi | 60 | fi |
61 | } | 61 | } |
62 | 62 | ||
63 | # Reason for this function is that on some systems | 63 | # Reason for this function is that on some systems |
64 | # smcup and rmcup are not knowing why left empty | 64 | # smcup and rmcup are not knowing why left empty |
65 | _nlist_alternate_screen() { | 65 | _nlist_alternate_screen() { |
66 | [ "$_nlist_has_terminfo" -ne "1" ] && return | 66 | [ "$_nlist_has_terminfo" -ne "1" ] && return |
67 | [[ "$1" = "1" && -n "$terminfo[smcup]" ]] && return | 67 | [[ "$1" = "1" && -n "$terminfo[smcup]" ]] && return |
68 | [[ "$1" = "0" && -n "$terminfo[rmcup]" ]] && return | 68 | [[ "$1" = "0" && -n "$terminfo[rmcup]" ]] && return |
69 | 69 | ||
70 | case "$TERM" in | 70 | case "$TERM" in |
71 | *rxvt*) | 71 | *rxvt*) |
72 | [ "$1" = "1" ] && echo -n $'\x1b7\x1b[?47h' | 72 | [ "$1" = "1" ] && echo -n $'\x1b7\x1b[?47h' |
73 | [ "$1" = "0" ] && echo -n $'\x1b[2J\x1b[?47l\x1b8' | 73 | [ "$1" = "0" ] && echo -n $'\x1b[2J\x1b[?47l\x1b8' |
74 | ;; | 74 | ;; |
75 | *) | 75 | *) |
76 | [ "$1" = "1" ] && echo -n $'\x1b[?1049h' | 76 | [ "$1" = "1" ] && echo -n $'\x1b[?1049h' |
77 | [ "$1" = "0" ] && echo -n $'\x1b[?1049l' | 77 | [ "$1" = "0" ] && echo -n $'\x1b[?1049l' |
78 | # just to remember two other that work: $'\x1b7\x1b[r\x1b[?47h', $'\x1b[?47l\x1b8' | 78 | # just to remember two other that work: $'\x1b7\x1b[r\x1b[?47h', $'\x1b[?47l\x1b8' |
79 | ;; | 79 | ;; |
80 | esac | 80 | esac |
81 | } | 81 | } |
82 | 82 | ||
83 | _nlist_compute_user_vars_difference() { | 83 | _nlist_compute_user_vars_difference() { |
84 | if [[ "${(t)NLIST_NONSELECTABLE_ELEMENTS}" != "array" && | 84 | if [[ "${(t)NLIST_NONSELECTABLE_ELEMENTS}" != "array" && |
85 | "${(t)NLIST_NONSELECTABLE_ELEMENTS}" != "array-local" ]] | 85 | "${(t)NLIST_NONSELECTABLE_ELEMENTS}" != "array-local" ]] |
86 | then | 86 | then |
87 | last_element_difference=0 | 87 | last_element_difference=0 |
88 | current_difference=0 | 88 | current_difference=0 |
89 | else | 89 | else |
90 | last_element_difference=$#NLIST_NONSELECTABLE_ELEMENTS | 90 | last_element_difference=$#NLIST_NONSELECTABLE_ELEMENTS |
91 | current_difference=0 | 91 | current_difference=0 |
92 | local idx | 92 | local idx |
93 | for idx in "${(n)NLIST_NONSELECTABLE_ELEMENTS[@]}"; do | 93 | for idx in "${(n)NLIST_NONSELECTABLE_ELEMENTS[@]}"; do |
94 | [ "$idx" -le "$NLIST_CURRENT_IDX" ] && current_difference+=1 || break | 94 | [ "$idx" -le "$NLIST_CURRENT_IDX" ] && current_difference+=1 || break |
95 | done | 95 | done |
96 | fi | 96 | fi |
97 | } | 97 | } |
98 | 98 | ||
99 | # List was processed, check if variables aren't off range | 99 | # List was processed, check if variables aren't off range |
100 | _nlist_verify_vars() { | 100 | _nlist_verify_vars() { |
101 | [ "$NLIST_CURRENT_IDX" -gt "$last_element" ] && NLIST_CURRENT_IDX="$last_element" | 101 | [ "$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 | 102 | [[ "$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 )) | 103 | (( NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN=0+((NLIST_CURRENT_IDX-1)/page_height)*page_height+1 )) |
104 | } | 104 | } |
105 | 105 | ||
106 | # Compute the variables which are shown to the user | 106 | # Compute the variables which are shown to the user |
107 | _nlist_setup_user_vars() { | 107 | _nlist_setup_user_vars() { |
108 | if [ "$1" = "1" ]; then | 108 | if [ "$1" = "1" ]; then |
109 | # Basic values when there are no non-selectables | 109 | # Basic values when there are no non-selectables |
110 | NLIST_USER_CURRENT_IDX="$NLIST_CURRENT_IDX" | 110 | NLIST_USER_CURRENT_IDX="$NLIST_CURRENT_IDX" |
111 | NLIST_USER_LAST_ELEMENT="$last_element" | 111 | NLIST_USER_LAST_ELEMENT="$last_element" |
112 | else | 112 | else |
113 | _nlist_compute_user_vars_difference | 113 | _nlist_compute_user_vars_difference |
114 | NLIST_USER_CURRENT_IDX=$(( NLIST_CURRENT_IDX - current_difference )) | 114 | NLIST_USER_CURRENT_IDX=$(( NLIST_CURRENT_IDX - current_difference )) |
115 | NLIST_USER_LAST_ELEMENT=$(( last_element - last_element_difference )) | 115 | NLIST_USER_LAST_ELEMENT=$(( last_element - last_element_difference )) |
116 | fi | 116 | fi |
117 | } | 117 | } |
118 | 118 | ||
119 | _nlist_coloring_list_into_col_list() { | 119 | _nlist_coloring_list_into_col_list() { |
120 | local col=$'\x1b[00;34m' reset=$'\x1b[0m' | 120 | local col=$'\x1b[00;34m' reset=$'\x1b[0m' |
121 | [ -n "$NLIST_COLORING_COLOR" ] && col="$NLIST_COLORING_COLOR" | 121 | [ -n "$NLIST_COLORING_COLOR" ] && col="$NLIST_COLORING_COLOR" |
122 | [ -n "$NLIST_COLORING_END_COLOR" ] && reset="$NLIST_COLORING_END_COLOR" | 122 | [ -n "$NLIST_COLORING_END_COLOR" ] && reset="$NLIST_COLORING_END_COLOR" |
123 | 123 | ||
124 | if [ "$NLIST_COLORING_MATCH_MULTIPLE" -eq 1 ]; then | 124 | if [ "$NLIST_COLORING_MATCH_MULTIPLE" -eq 1 ]; then |
125 | col_list=( "${(@)list//(#mi)$~NLIST_COLORING_PATTERN/$col${MATCH}$reset}" ) | 125 | col_list=( "${(@)list//(#mi)$~NLIST_COLORING_PATTERN/$col${MATCH}$reset}" ) |
126 | else | 126 | else |
127 | col_list=( "${(@)list/(#mi)$~NLIST_COLORING_PATTERN/$col${MATCH}$reset}" ) | 127 | col_list=( "${(@)list/(#mi)$~NLIST_COLORING_PATTERN/$col${MATCH}$reset}" ) |
128 | fi | 128 | fi |
129 | } | 129 | } |
130 | 130 | ||
131 | # | 131 | # |
132 | # Main code | 132 | # Main code |
133 | # | 133 | # |
134 | 134 | ||
135 | # Check if there is proper input | 135 | # Check if there is proper input |
136 | if [ "$#" -lt 1 ]; then | 136 | if [ "$#" -lt 1 ]; then |
137 | echo "Usage: n-list element_1 ..." | 137 | echo "Usage: n-list element_1 ..." |
138 | return 1 | 138 | return 1 |
139 | fi | 139 | fi |
140 | 140 | ||
141 | REPLY="-1" | 141 | REPLY="-1" |
142 | typeset -ga reply | 142 | typeset -ga reply |
143 | reply=() | 143 | reply=() |
144 | 144 | ||
145 | integer term_height="$LINES" | 145 | integer term_height="$LINES" |
146 | integer term_width="$COLUMNS" | 146 | integer term_width="$COLUMNS" |
147 | if [[ "$term_height" -lt 1 || "$term_width" -lt 1 ]]; then | 147 | if [[ "$term_height" -lt 1 || "$term_width" -lt 1 ]]; then |
148 | local stty_out=$( stty size ) | 148 | local stty_out=$( stty size ) |
149 | term_height="${stty_out% *}" | 149 | term_height="${stty_out% *}" |
150 | term_width="${stty_out#* }" | 150 | term_width="${stty_out#* }" |
151 | fi | 151 | fi |
152 | integer inner_height=term_height-3 | 152 | integer inner_height=term_height-3 |
153 | integer inner_width=term_width-3 | 153 | integer inner_width=term_width-3 |
154 | integer page_height=inner_height | 154 | integer page_height=inner_height |
155 | integer page_width=inner_width | 155 | integer page_width=inner_width |
156 | 156 | ||
157 | typeset -a list col_list disp_list | 157 | typeset -a list col_list disp_list |
158 | integer last_element=$# | 158 | integer last_element=$# |
159 | local action | 159 | local action |
160 | local final_key | 160 | local final_key |
161 | integer selection | 161 | integer selection |
162 | integer last_element_difference=0 | 162 | integer last_element_difference=0 |
163 | integer current_difference=0 | 163 | integer current_difference=0 |
164 | local prev_search_buffer="" | 164 | local prev_search_buffer="" |
165 | integer prev_uniq_mode=0 | 165 | integer prev_uniq_mode=0 |
166 | integer prev_start_idx=-1 | 166 | integer prev_start_idx=-1 |
167 | 167 | ||
168 | # Ability to remember the list between calls | 168 | # Ability to remember the list between calls |
169 | if [[ -z "$NLIST_REMEMBER_STATE" || "$NLIST_REMEMBER_STATE" -eq 0 || "$NLIST_REMEMBER_STATE" -eq 2 ]]; then | 169 | 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 | 170 | NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN=1 |
171 | NLIST_CURRENT_IDX=1 | 171 | NLIST_CURRENT_IDX=1 |
172 | NLIST_IS_SEARCH_MODE=0 | 172 | NLIST_IS_SEARCH_MODE=0 |
173 | NLIST_SEARCH_BUFFER="" | 173 | NLIST_SEARCH_BUFFER="" |
174 | NLIST_TEXT_OFFSET=0 | 174 | NLIST_TEXT_OFFSET=0 |
175 | NLIST_IS_UNIQ_MODE=0 | 175 | NLIST_IS_UNIQ_MODE=0 |
176 | 176 | ||
177 | # Zero - because it isn't known, unless we | 177 | # Zero - because it isn't known, unless we |
178 | # confirm that first element is selectable | 178 | # confirm that first element is selectable |
179 | NLIST_USER_CURRENT_IDX=0 | 179 | NLIST_USER_CURRENT_IDX=0 |
180 | [[ ${NLIST_NONSELECTABLE_ELEMENTS[(r)1]} != 1 ]] && NLIST_USER_CURRENT_IDX=1 | 180 | [[ ${NLIST_NONSELECTABLE_ELEMENTS[(r)1]} != 1 ]] && NLIST_USER_CURRENT_IDX=1 |
181 | NLIST_USER_LAST_ELEMENT=$(( last_element - $#NLIST_NONSELECTABLE_ELEMENTS )) | 181 | NLIST_USER_LAST_ELEMENT=$(( last_element - $#NLIST_NONSELECTABLE_ELEMENTS )) |
182 | 182 | ||
183 | # 2 is init once, then remember | 183 | # 2 is init once, then remember |
184 | [ "$NLIST_REMEMBER_STATE" -eq 2 ] && NLIST_REMEMBER_STATE=1 | 184 | [ "$NLIST_REMEMBER_STATE" -eq 2 ] && NLIST_REMEMBER_STATE=1 |
185 | fi | 185 | fi |
186 | 186 | ||
187 | if [ "$NLIST_START_IN_SEARCH_MODE" -eq 1 ]; then | 187 | if [ "$NLIST_START_IN_SEARCH_MODE" -eq 1 ]; then |
188 | NLIST_START_IN_SEARCH_MODE=0 | 188 | NLIST_START_IN_SEARCH_MODE=0 |
189 | NLIST_IS_SEARCH_MODE=1 | 189 | NLIST_IS_SEARCH_MODE=1 |
190 | fi | 190 | fi |
191 | 191 | ||
192 | if [ -n "$NLIST_SET_SEARCH_TO" ]; then | 192 | if [ -n "$NLIST_SET_SEARCH_TO" ]; then |
193 | NLIST_SEARCH_BUFFER="$NLIST_SET_SEARCH_TO" | 193 | NLIST_SEARCH_BUFFER="$NLIST_SET_SEARCH_TO" |
194 | NLIST_SET_SEARCH_TO="" | 194 | NLIST_SET_SEARCH_TO="" |
195 | fi | 195 | fi |
196 | 196 | ||
197 | if [ "$NLIST_START_IN_UNIQ_MODE" -eq 1 ]; then | 197 | if [ "$NLIST_START_IN_UNIQ_MODE" -eq 1 ]; then |
198 | NLIST_START_IN_UNIQ_MODE=0 | 198 | NLIST_START_IN_UNIQ_MODE=0 |
199 | NLIST_IS_UNIQ_MODE=1 | 199 | NLIST_IS_UNIQ_MODE=1 |
200 | fi | 200 | fi |
201 | 201 | ||
202 | _nlist_alternate_screen 1 | 202 | _nlist_alternate_screen 1 |
203 | zcurses init | 203 | zcurses init |
204 | zcurses delwin main 2>/dev/null | 204 | zcurses delwin main 2>/dev/null |
205 | zcurses delwin inner 2>/dev/null | 205 | zcurses delwin inner 2>/dev/null |
206 | zcurses addwin main "$term_height" "$term_width" 0 0 | 206 | zcurses addwin main "$term_height" "$term_width" 0 0 |
207 | zcurses addwin inner "$inner_height" "$inner_width" 1 2 | 207 | zcurses addwin inner "$inner_height" "$inner_width" 1 2 |
208 | zcurses bg main white/black | 208 | zcurses bg main white/black |
209 | zcurses bg inner white/black | 209 | zcurses bg inner white/black |
210 | if [ "$NLIST_IS_SEARCH_MODE" -ne 1 ]; then | 210 | if [ "$NLIST_IS_SEARCH_MODE" -ne 1 ]; then |
211 | _nlist_cursor_visibility 0 | 211 | _nlist_cursor_visibility 0 |
212 | fi | 212 | fi |
213 | 213 | ||
214 | # | 214 | # |
215 | # Listening for input | 215 | # Listening for input |
216 | # | 216 | # |
217 | 217 | ||
218 | local key keypad | 218 | local key keypad |
219 | 219 | ||
220 | # Clear input buffer | 220 | # Clear input buffer |
221 | zcurses timeout main 0 | 221 | zcurses timeout main 0 |
222 | zcurses input main key keypad | 222 | zcurses input main key keypad |
223 | zcurses timeout main -1 | 223 | zcurses timeout main -1 |
224 | key="" | 224 | key="" |
225 | keypad="" | 225 | keypad="" |
226 | 226 | ||
227 | list=( "$@" ) | 227 | list=( "$@" ) |
228 | last_element="$#list" | 228 | last_element="$#list" |
229 | 229 | ||
230 | integer is_colored=0 | 230 | integer is_colored=0 |
231 | if [[ -z "$NLIST_SEARCH_BUFFER" && -n "$NLIST_COLORING_PATTERN" ]]; then | 231 | if [[ -z "$NLIST_SEARCH_BUFFER" && -n "$NLIST_COLORING_PATTERN" ]]; then |
232 | is_colored=1 | 232 | is_colored=1 |
233 | _nlist_coloring_list_into_col_list | 233 | _nlist_coloring_list_into_col_list |
234 | fi | 234 | fi |
235 | 235 | ||
236 | while (( 1 )); do | 236 | while (( 1 )); do |
237 | # Do searching (filtering with string) | 237 | # Do searching (filtering with string) |
238 | if [ -n "$NLIST_SEARCH_BUFFER" ]; then | 238 | if [ -n "$NLIST_SEARCH_BUFFER" ]; then |
239 | # Compute new list, col_list ? | 239 | # Compute new list, col_list ? |
240 | 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 |
241 | prev_search_buffer="$NLIST_SEARCH_BUFFER" | 241 | prev_search_buffer="$NLIST_SEARCH_BUFFER" |
242 | prev_uniq_mode="$NLIST_IS_UNIQ_MODE" | 242 | prev_uniq_mode="$NLIST_IS_UNIQ_MODE" |
243 | # regenerating list -> regenerating disp_list | 243 | # regenerating list -> regenerating disp_list |
244 | prev_start_idx=-1 | 244 | prev_start_idx=-1 |
245 | 245 | ||
246 | # Take all elements, including duplicates and non-selectables | 246 | # Take all elements, including duplicates and non-selectables |
247 | typeset +U list | 247 | typeset +U list |
248 | list=( "$@" ) | 248 | list=( "$@" ) |
249 | 249 | ||
250 | # Remove non-selectable elements | 250 | # Remove non-selectable elements |
251 | [ "$#NLIST_NONSELECTABLE_ELEMENTS" -gt 0 ] && for i in "${(nO)NLIST_NONSELECTABLE_ELEMENTS[@]}"; do | 251 | [ "$#NLIST_NONSELECTABLE_ELEMENTS" -gt 0 ] && for i in "${(nO)NLIST_NONSELECTABLE_ELEMENTS[@]}"; do |
252 | list[$i]=() | 252 | list[$i]=() |
253 | done | 253 | done |
254 | 254 | ||
255 | # Remove duplicates | 255 | # Remove duplicates |
256 | [ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && typeset -U list | 256 | [ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && typeset -U list |
257 | 257 | ||
258 | last_element="$#list" | 258 | last_element="$#list" |
259 | 259 | ||
260 | # Next do the filtering | 260 | # Next do the filtering |
261 | local search_buffer="${NLIST_SEARCH_BUFFER%% ##}" | 261 | local search_buffer="${NLIST_SEARCH_BUFFER%% ##}" |
262 | search_buffer="${search_buffer## ##}" | 262 | search_buffer="${search_buffer## ##}" |
263 | search_buffer="${search_buffer//(#m)[][*?|#~^()><\\]/\\$MATCH}" | 263 | search_buffer="${search_buffer//(#m)[][*?|#~^()><\\]/\\$MATCH}" |
264 | local search_pattern="" | ||
265 | local colsearch_pattern="" | ||
264 | if [ -n "$search_buffer" ]; then | 266 | if [ -n "$search_buffer" ]; then |
265 | # Patterns will be *foo*~^*bar* and foo|bar) | 267 | # Patterns will be *foo*~^*bar* and foo|bar) |
266 | local search_pattern="${search_buffer// ##/*~^*}" | 268 | search_pattern="${search_buffer// ##/*~^*}" |
267 | local colsearch_pattern="${search_buffer// ##/|}" | 269 | colsearch_pattern="${search_buffer// ##/|}" |
268 | 270 | ||
269 | list=( "${(@M)list:#(#i)*$~search_pattern*}" ) | 271 | list=( "${(@M)list:#(#i)*$~search_pattern*}" ) |
270 | last_element="$#list" | 272 | last_element="$#list" |
271 | |||
272 | local red=$'\x1b[00;31m' reset=$'\x1b[00;00m' | ||
273 | col_list=( "${(@)list//(#mi)($~colsearch_pattern)/$red${MATCH}$reset}" ) | ||
274 | else | ||
275 | col_list=( "$list[@]" ) | ||
276 | fi | 273 | fi |
277 | 274 | ||
278 | # Called after processing list | 275 | # Called after processing list |
279 | _nlist_verify_vars | 276 | _nlist_verify_vars |
280 | fi | 277 | fi |
281 | 278 | ||
282 | _nlist_setup_user_vars 1 | 279 | _nlist_setup_user_vars 1 |
283 | 280 | ||
284 | integer end_idx=$(( NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN + page_height - 1 )) | 281 | integer end_idx=$(( NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN + page_height - 1 )) |
285 | [ "$end_idx" -gt "$last_element" ] && end_idx=last_element | 282 | [ "$end_idx" -gt "$last_element" ] && end_idx=last_element |
286 | 283 | ||
287 | if [ "$prev_start_idx" -ne "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" ]; then | 284 | if [ "$prev_start_idx" -ne "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" ]; then |
288 | prev_start_idx="$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" | 285 | prev_start_idx="$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" |
289 | disp_list=( "${(@)col_list[NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN, end_idx]}" ) | 286 | disp_list=( "${(@)list[NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN, end_idx]}" ) |
287 | |||
288 | if [ -n "$colsearch_pattern" ]; then | ||
289 | local red=$'\x1b[00;31m' reset=$'\x1b[00;00m' | ||
290 | disp_list=( "${(@)disp_list//(#mi)($~colsearch_pattern)/$red${MATCH}$reset}" ) | ||
291 | fi | ||
290 | 292 | ||
291 | # We have display list, lets replace newlines with "\n" when needed (1/3) | 293 | # We have display list, lets replace newlines with "\n" when needed (1/3) |
292 | [ "$NLIST_REPLACE_NEWLINES" -eq 1 ] && disp_list=( "${(@)disp_list//$'\n'/\\n}" ) | 294 | [ "$NLIST_REPLACE_NEWLINES" -eq 1 ] && disp_list=( "${(@)disp_list//$'\n'/\\n}" ) |
293 | fi | 295 | fi |
294 | 296 | ||
295 | # Output colored list | 297 | # Output colored list |
296 | n-list-draw "$(( (NLIST_CURRENT_IDX-1) % page_height + 1 ))" \ | 298 | n-list-draw "$(( (NLIST_CURRENT_IDX-1) % page_height + 1 ))" \ |
297 | "$page_height" "$page_width" 0 0 "$NLIST_TEXT_OFFSET" inner \ | 299 | "$page_height" "$page_width" 0 0 "$NLIST_TEXT_OFFSET" inner \ |
298 | "$disp_list[@]" | 300 | "$disp_list[@]" |
299 | else | 301 | else |
300 | # There is no search, but there was in previous loop | 302 | # There is no search, but there was in previous loop |
301 | # OR | 303 | # OR |
302 | # Uniq mode was entered or left out | 304 | # Uniq mode was entered or left out |
303 | # -> compute new list (maybe also col_list) | 305 | # -> compute new list (maybe also col_list) |
304 | if [[ -n "$prev_search_buffer" || "$NLIST_IS_UNIQ_MODE" -ne "$prev_uniq_mode" ]]; then | 306 | if [[ -n "$prev_search_buffer" || "$NLIST_IS_UNIQ_MODE" -ne "$prev_uniq_mode" ]]; then |
305 | prev_search_buffer="" | 307 | prev_search_buffer="" |
306 | prev_uniq_mode="$NLIST_IS_UNIQ_MODE" | 308 | prev_uniq_mode="$NLIST_IS_UNIQ_MODE" |
307 | # regenerating list -> regenerating disp_list | 309 | # regenerating list -> regenerating disp_list |
308 | prev_start_idx=-1 | 310 | prev_start_idx=-1 |
309 | 311 | ||
310 | # Take all elements, including duplicates and non-selectables | 312 | # Take all elements, including duplicates and non-selectables |
311 | typeset +U list | 313 | typeset +U list |
312 | list=( "$@" ) | 314 | list=( "$@" ) |
313 | 315 | ||
314 | # Remove non-selectable elements only when in uniq mode | 316 | # Remove non-selectable elements only when in uniq mode |
315 | [ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && [ "$#NLIST_NONSELECTABLE_ELEMENTS" -gt 0 ] && | 317 | [ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && [ "$#NLIST_NONSELECTABLE_ELEMENTS" -gt 0 ] && |
316 | for i in "${(nO)NLIST_NONSELECTABLE_ELEMENTS[@]}"; do | 318 | for i in "${(nO)NLIST_NONSELECTABLE_ELEMENTS[@]}"; do |
317 | list[$i]=() | 319 | list[$i]=() |
318 | done | 320 | done |
319 | 321 | ||
320 | # Remove duplicates when in uniq mode | 322 | # Remove duplicates when in uniq mode |
321 | [ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && typeset -U list | 323 | [ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && typeset -U list |
322 | 324 | ||
323 | # Apply coloring pattern (when not with search query) | 325 | # Apply coloring pattern (when not with search query) |
324 | is_colored=0 | 326 | is_colored=0 |
325 | if [ -n "$NLIST_COLORING_PATTERN" ]; then | 327 | if [ -n "$NLIST_COLORING_PATTERN" ]; then |
326 | is_colored=1 | 328 | is_colored=1 |
327 | _nlist_coloring_list_into_col_list | 329 | _nlist_coloring_list_into_col_list |
328 | fi | 330 | fi |
329 | 331 | ||
330 | last_element="$#list" | 332 | last_element="$#list" |
331 | # Called after processing list | 333 | # Called after processing list |
332 | _nlist_verify_vars | 334 | _nlist_verify_vars |
333 | fi | 335 | fi |
334 | 336 | ||
335 | # "1" - shouldn't bother with non-selectables | 337 | # "1" - shouldn't bother with non-selectables |
336 | _nlist_setup_user_vars "$NLIST_IS_UNIQ_MODE" | 338 | _nlist_setup_user_vars "$NLIST_IS_UNIQ_MODE" |
337 | 339 | ||
338 | integer end_idx=$(( NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN + page_height - 1 )) | 340 | integer end_idx=$(( NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN + page_height - 1 )) |
339 | [ "$end_idx" -gt "$last_element" ] && end_idx=last_element | 341 | [ "$end_idx" -gt "$last_element" ] && end_idx=last_element |
340 | 342 | ||
341 | if [ "$is_colored" -eq 0 ]; then | 343 | if [ "$is_colored" -eq 0 ]; then |
342 | if [ "$prev_start_idx" -ne "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" ]; then | 344 | if [ "$prev_start_idx" -ne "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" ]; then |
343 | prev_start_idx="$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" | 345 | prev_start_idx="$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" |
344 | disp_list=( "${(@)list[NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN, end_idx]}" ) | 346 | disp_list=( "${(@)list[NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN, end_idx]}" ) |
345 | 347 | ||
346 | # We have display list, lets replace newlines with "\n" when needed (2/3) | 348 | # We have display list, lets replace newlines with "\n" when needed (2/3) |
347 | [ "$NLIST_REPLACE_NEWLINES" -eq 1 ] && disp_list=( "${(@)disp_list//$'\n'/\\n}" ) | 349 | [ "$NLIST_REPLACE_NEWLINES" -eq 1 ] && disp_list=( "${(@)disp_list//$'\n'/\\n}" ) |
348 | fi | 350 | fi |
349 | else | 351 | else |
350 | if [ "$prev_start_idx" -ne "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" ]; then | 352 | if [ "$prev_start_idx" -ne "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" ]; then |
351 | prev_start_idx="$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" | 353 | prev_start_idx="$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" |
352 | disp_list=( "${(@)col_list[NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN, end_idx]}" ) | 354 | disp_list=( "${(@)col_list[NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN, end_idx]}" ) |
353 | 355 | ||
354 | # We have display list, lets replace newlines with "\n" when needed (3/3) | 356 | # We have display list, lets replace newlines with "\n" when needed (3/3) |
355 | [ "$NLIST_REPLACE_NEWLINES" -eq 1 ] && disp_list=( "${(@)disp_list//$'\n'/\\n}" ) | 357 | [ "$NLIST_REPLACE_NEWLINES" -eq 1 ] && disp_list=( "${(@)disp_list//$'\n'/\\n}" ) |
356 | fi | 358 | fi |
357 | fi | 359 | fi |
358 | 360 | ||
359 | # Output the list | 361 | # Output the list |
360 | n-list-draw "$(( (NLIST_CURRENT_IDX-1) % page_height + 1 ))" \ | 362 | n-list-draw "$(( (NLIST_CURRENT_IDX-1) % page_height + 1 ))" \ |
361 | "$page_height" "$page_width" 0 0 "$NLIST_TEXT_OFFSET" inner \ | 363 | "$page_height" "$page_width" 0 0 "$NLIST_TEXT_OFFSET" inner \ |
362 | "$disp_list[@]" | 364 | "$disp_list[@]" |
363 | fi | 365 | fi |
364 | 366 | ||
365 | local status_msg_strlen | 367 | local status_msg_strlen |
366 | if [ "$NLIST_IS_SEARCH_MODE" = "1" ]; then | 368 | if [ "$NLIST_IS_SEARCH_MODE" = "1" ]; then |
367 | local _txt2="" | 369 | local _txt2="" |
368 | [ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && _txt2="[-UNIQ-] " | 370 | [ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && _txt2="[-UNIQ-] " |
369 | _nlist_status_msg "${_txt2}Filtering with: ${NLIST_SEARCH_BUFFER// /+}" | 371 | _nlist_status_msg "${_txt2}Filtering with: ${NLIST_SEARCH_BUFFER// /+}" |
370 | elif [[ ${NLIST_NONSELECTABLE_ELEMENTS[(r)$NLIST_CURRENT_IDX]} != $NLIST_CURRENT_IDX || | 372 | elif [[ ${NLIST_NONSELECTABLE_ELEMENTS[(r)$NLIST_CURRENT_IDX]} != $NLIST_CURRENT_IDX || |
371 | -n "$NLIST_SEARCH_BUFFER" || "$NLIST_IS_UNIQ_MODE" -eq 1 ]]; then | 373 | -n "$NLIST_SEARCH_BUFFER" || "$NLIST_IS_UNIQ_MODE" -eq 1 ]]; then |
372 | local _txt="" _txt2="" | 374 | local _txt="" _txt2="" |
373 | [ -n "$NLIST_GREP_STRING" ] && _txt=" [$NLIST_GREP_STRING]" | 375 | [ -n "$NLIST_GREP_STRING" ] && _txt=" [$NLIST_GREP_STRING]" |
374 | [ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && _txt2="[-UNIQ-] " | 376 | [ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && _txt2="[-UNIQ-] " |
375 | _nlist_status_msg "${_txt2}Current #$NLIST_USER_CURRENT_IDX (of #$NLIST_USER_LAST_ELEMENT entries)$_txt" | 377 | _nlist_status_msg "${_txt2}Current #$NLIST_USER_CURRENT_IDX (of #$NLIST_USER_LAST_ELEMENT entries)$_txt" |
376 | else | 378 | else |
377 | _nlist_status_msg "" | 379 | _nlist_status_msg "" |
378 | fi | 380 | fi |
379 | 381 | ||
380 | zcurses border main | 382 | zcurses border main |
381 | zcurses refresh main inner | 383 | zcurses refresh main inner |
382 | zcurses move main $(( term_height - 1 - 1 )) $(( status_msg_strlen + 2 )) | 384 | zcurses move main $(( term_height - 1 - 1 )) $(( status_msg_strlen + 2 )) |
383 | 385 | ||
384 | # Wait for input | 386 | # Wait for input |
385 | zcurses input main key keypad | 387 | zcurses input main key keypad |
386 | 388 | ||
387 | # Get the special (i.e. "keypad") key or regular key | 389 | # Get the special (i.e. "keypad") key or regular key |
388 | if [ -n "$key" ]; then | 390 | if [ -n "$key" ]; then |
389 | final_key="$key" | 391 | final_key="$key" |
390 | elif [ -n "$keypad" ]; then | 392 | elif [ -n "$keypad" ]; then |
391 | final_key="$keypad" | 393 | final_key="$keypad" |
392 | else | 394 | else |
393 | _nlist_status_msg "Inproper input detected" | 395 | _nlist_status_msg "Inproper input detected" |
394 | zcurses refresh main inner | 396 | zcurses refresh main inner |
395 | fi | 397 | fi |
396 | 398 | ||
397 | n-list-input "$NLIST_CURRENT_IDX" "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" \ | 399 | n-list-input "$NLIST_CURRENT_IDX" "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" \ |
398 | "$page_height" "$page_width" "$last_element" "$NLIST_TEXT_OFFSET" \ | 400 | "$page_height" "$page_width" "$last_element" "$NLIST_TEXT_OFFSET" \ |
399 | "$final_key" "$NLIST_IS_SEARCH_MODE" "$NLIST_SEARCH_BUFFER" \ | 401 | "$final_key" "$NLIST_IS_SEARCH_MODE" "$NLIST_SEARCH_BUFFER" \ |
400 | "$NLIST_IS_UNIQ_MODE" | 402 | "$NLIST_IS_UNIQ_MODE" |
401 | 403 | ||
402 | selection="$reply[1]" | 404 | selection="$reply[1]" |
403 | action="$reply[2]" | 405 | action="$reply[2]" |
404 | NLIST_CURRENT_IDX="$reply[3]" | 406 | NLIST_CURRENT_IDX="$reply[3]" |
405 | NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN="$reply[4]" | 407 | NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN="$reply[4]" |
406 | NLIST_TEXT_OFFSET="$reply[5]" | 408 | NLIST_TEXT_OFFSET="$reply[5]" |
407 | NLIST_IS_SEARCH_MODE="$reply[6]" | 409 | NLIST_IS_SEARCH_MODE="$reply[6]" |
408 | NLIST_SEARCH_BUFFER="$reply[7]" | 410 | NLIST_SEARCH_BUFFER="$reply[7]" |
409 | NLIST_IS_UNIQ_MODE="$reply[8]" | 411 | NLIST_IS_UNIQ_MODE="$reply[8]" |
410 | 412 | ||
411 | if [ "$action" = "SELECT" ]; then | 413 | if [ "$action" = "SELECT" ]; then |
412 | REPLY="$selection" | 414 | REPLY="$selection" |
413 | reply=( "$list[@]" ) | 415 | reply=( "$list[@]" ) |
414 | break | 416 | break |
415 | elif [ "$action" = "QUIT" ]; then | 417 | elif [ "$action" = "QUIT" ]; then |
416 | REPLY=-1 | 418 | REPLY=-1 |
417 | reply=( "$list[@]" ) | 419 | reply=( "$list[@]" ) |
418 | break | 420 | break |
419 | elif [ "$action" = "REDRAW" ]; then | 421 | elif [ "$action" = "REDRAW" ]; then |
420 | zcurses clear main redraw | 422 | zcurses clear main redraw |
421 | zcurses clear inner redraw | 423 | zcurses clear inner redraw |
-
mentioned in commit 9284fe