diff options
author | Marc Cornellà <marc.cornella@live.com> | 2015-11-30 09:50:37 +0100 |
---|---|---|
committer | Marc Cornellà <marc.cornella@live.com> | 2015-11-30 09:50:37 +0100 |
commit | afd28bf1fc22f53c4a1af3f5836ca428affb34b3 (patch) | |
tree | 9f56960cbb4e2074d405e4be587a1658a6cc2159 /plugins/zsh-navigation-tools/n-panelize | |
parent | fea74b4b34412cca1b0bc3ec232e5ec8c602ee8a (diff) | |
parent | 4c292ea2b023a331dcf1af5644487f2272d24a4d (diff) | |
download | zsh-afd28bf1fc22f53c4a1af3f5836ca428affb34b3.tar.gz zsh-afd28bf1fc22f53c4a1af3f5836ca428affb34b3.tar.bz2 zsh-afd28bf1fc22f53c4a1af3f5836ca428affb34b3.zip |
Merge pull request #4368 from psprint/master
Update Zsh Navigation Tools plugin
Diffstat (limited to 'plugins/zsh-navigation-tools/n-panelize')
-rw-r--r-- | plugins/zsh-navigation-tools/n-panelize | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/plugins/zsh-navigation-tools/n-panelize b/plugins/zsh-navigation-tools/n-panelize new file mode 100644 index 000000000..a70565c79 --- /dev/null +++ b/plugins/zsh-navigation-tools/n-panelize @@ -0,0 +1,61 @@ +# Copy this file into /usr/share/zsh/site-functions/ +# and add 'autoload n-panelize` to .zshrc +# +# This function somewhat reminds the panelize feature from Midnight Commander +# It allows browsing output of arbitrary command. Example usage: +# v-panelize ls /usr/local/bin +# +# Uses n-list + +emulate -L zsh + +setopt extendedglob +zmodload zsh/curses + +local IFS=" +" + +unset NLIST_COLORING_PATTERN + +[ -f ~/.config/znt/n-list.conf ] && . ~/.config/znt/n-list.conf +[ -f ~/.config/znt/n-panelize.conf ] && . ~/.config/znt/n-panelize.conf + +local list +local selected + +NLIST_REMEMBER_STATE=0 + +if [ -t 0 ]; then + # Check if there is proper input + if [ "$#" -lt 1 ]; then + echo "Usage: n-panelize {command} [option|argument] ... or command | n-panelize" + return 1 + fi + + list=( `"$@"` ) + # TODO: $? doesn't reach user + [ "$?" -eq 127 ] && return $? +else + # Check if can reattach to terminal + if [[ ! -c /dev/tty && ! -t 2 ]]; then + echo "No terminal available (no /dev/tty)" + return 1 + fi + + list=( "${(@f)"$(<&0)"}" ) + + if [[ ! -c /dev/tty ]]; then + exec <&2 + else + exec </dev/tty + fi +fi + +n-list "${list[@]}" + +if [ "$REPLY" -gt 0 ]; then + selected="$reply[REPLY]" + print -zr "# $selected" +fi + +# vim: set filetype=zsh: |