Blame view
plugins/zsh-navigation-tools/n-panelize
1.46 KB
|
7378b55de
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# 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 |
|
d9bebbb3c
|
19 20 |
[ -f ~/.config/znt/n-list.conf ] && builtin source ~/.config/znt/n-list.conf [ -f ~/.config/znt/n-panelize.conf ] && builtin source ~/.config/znt/n-panelize.conf |
|
7378b55de
|
21 22 23 24 25 26 27 28 29 30 31 32 |
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
|
|
61aaa7b58
|
33 34 35 36 |
# This loop makes script faster on some Zsh's (e.g. 5.0.8)
repeat 1; do
list=( `"$@"` )
done
|
|
7378b55de
|
37 38 39 40 41 42 43 44 |
# 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
|
|
61aaa7b58
|
45 46 47 48 |
# This loop makes script faster on some Zsh's (e.g. 5.0.8)
repeat 1; do
list=( "${(@f)"$(<&0)"}" )
done
|
|
7378b55de
|
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
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:
|