]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/zsh-navigation-tools/n-panelize
...
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / zsh-navigation-tools / n-panelize
1 # Copy this file into /usr/share/zsh/site-functions/
2 # and add 'autoload n-panelize` to .zshrc
3 #
4 # This function somewhat reminds the panelize feature from Midnight Commander
5 # It allows browsing output of arbitrary command. Example usage:
6 # v-panelize ls /usr/local/bin
7 #
8 # Uses n-list
9
10 emulate -L zsh
11
12 setopt extendedglob
13 zmodload zsh/curses
14
15 local IFS="
16 "
17
18 unset NLIST_COLORING_PATTERN
19
20 [ -f ~/.config/znt/n-list.conf ] && builtin source ~/.config/znt/n-list.conf
21 [ -f ~/.config/znt/n-panelize.conf ] && builtin source ~/.config/znt/n-panelize.conf
22
23 local list
24 local selected
25
26 NLIST_REMEMBER_STATE=0
27
28 if [ -t 0 ]; then
29     # Check if there is proper input
30     if [ "$#" -lt 1 ]; then
31         echo "Usage: n-panelize {command} [option|argument] ... or command | n-panelize"
32         return 1
33     fi
34
35     # This loop makes script faster on some Zsh's (e.g. 5.0.8)
36     repeat 1; do
37         list=( `"$@"` )
38     done
39
40     # TODO: $? doesn't reach user
41     [ "$?" -eq 127 ] && return $?
42 else
43     # Check if can reattach to terminal
44     if [[ ! -c /dev/tty && ! -t 2 ]]; then
45         echo "No terminal available (no /dev/tty)"
46         return 1
47     fi
48
49     # This loop makes script faster on some Zsh's (e.g. 5.0.8)
50     repeat 1; do
51         list=( "${(@f)"$(<&0)"}" )
52     done
53
54     if [[ ! -c /dev/tty ]]; then
55         exec <&2
56     else
57         exec </dev/tty
58     fi
59 fi
60
61 n-list "${list[@]}"
62
63 if [ "$REPLY" -gt 0 ]; then
64     selected="$reply[REPLY]"
65     print -zr "# $selected"
66 fi
67
68 # vim: set filetype=zsh: