mirror of
https://github.com/dylanaraps/shfm.git
synced 2026-11-27 20:48:18 +00:00
drop all [
This commit is contained in:
2 files changed
+56
-41
No files matched your search
@@ -11,7 +11,7 @@ ________________________________________________________________________________
|
|||||||
based on shitty read timeouts (can't do 'em anyway). Instead based on tracking
|
based on shitty read timeouts (can't do 'em anyway). Instead based on tracking
|
||||||
position within escape sequences.
|
position within escape sequences.
|
||||||
|
|
||||||
* no dependencies other than a POSIX shell and POSIX (printf, dd, [ and stty)
|
* no dependencies other than a POSIX shell and POSIX (just printf, dd and stty)
|
||||||
|
|
||||||
* tiny?
|
* tiny?
|
||||||
|
|
||||||
|
|||||||
@@ -24,12 +24,12 @@ term_resize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hist_search() {
|
hist_search() {
|
||||||
hist=
|
hist=0 j=1
|
||||||
j=1
|
|
||||||
|
|
||||||
for file do
|
for file do
|
||||||
[ "${PWD%%/}/$file" = "$old_pwd" ] &&
|
case ${PWD%%/}/$file in
|
||||||
y=$j y2=$((j > bottom ? bottom : j))
|
"$old_pwd") y=$j y2=$((j > bottom ? bottom : j))
|
||||||
|
esac
|
||||||
|
|
||||||
j=$((j + 1))
|
j=$((j + 1))
|
||||||
done
|
done
|
||||||
@@ -41,18 +41,22 @@ list_print() {
|
|||||||
i=1
|
i=1
|
||||||
end=$((bottom + 1))
|
end=$((bottom + 1))
|
||||||
|
|
||||||
[ "$hist" ] &&
|
case $hist in
|
||||||
hist_search "$@"
|
1) hist_search "$@"
|
||||||
|
esac
|
||||||
|
|
||||||
[ "$y" -gt "$bottom" ] &&
|
case $((y - bottom)) in
|
||||||
shift "$((y - bottom))"
|
[0-9]*) shift "$((y - bottom))"
|
||||||
|
esac
|
||||||
|
|
||||||
for file do
|
for file do
|
||||||
[ "$i" = "$y2" ] &&
|
case $i in
|
||||||
printf '\033[31;7m'
|
"$y2") printf '\033[31;7m'
|
||||||
|
esac
|
||||||
|
|
||||||
[ "$i" -lt "$end" ] &&
|
case $((i - end)) in
|
||||||
printf '%s\033[m\033[B\r' "$file"
|
-*) printf '%s\033[m\033[B\r' "$file"
|
||||||
|
esac
|
||||||
|
|
||||||
i=$((i + 1))
|
i=$((i + 1))
|
||||||
done
|
done
|
||||||
@@ -73,64 +77,75 @@ status_line() {
|
|||||||
print_line() {
|
print_line() {
|
||||||
offset=$1
|
offset=$1
|
||||||
|
|
||||||
[ "$offset" != "$y" ] ||
|
case $offset in
|
||||||
printf '\033[31;7m'
|
"$y") printf '\033[31;7m'
|
||||||
|
esac
|
||||||
|
|
||||||
shift "$offset"
|
shift "$offset"
|
||||||
printf '\033[K%s\033[m\r' "$1"
|
printf '\033[K%s\033[m\r' "$1"
|
||||||
|
|
||||||
[ "$offset" != "$y" ] ||
|
case $offset in
|
||||||
cur=$1
|
"$y") cur=$1
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
esc_char=$(printf '\033')
|
esc_char=$(printf '\033')
|
||||||
|
|
||||||
# change directory to the first argument
|
|
||||||
cd "${1:-"$PWD"}"
|
cd "${1:-"$PWD"}"
|
||||||
|
|
||||||
set -- *
|
set -- *
|
||||||
|
|
||||||
term_resize
|
term_resize
|
||||||
term_setup
|
term_setup
|
||||||
y=1 y2=1
|
|
||||||
redraw "$@"
|
|
||||||
|
|
||||||
trap 'term_reset' EXIT INT
|
trap 'term_reset' EXIT INT
|
||||||
trap 'term_resize; term_setup; y=1 y2=1; redraw "$@"' WINCH
|
trap 'term_resize; term_setup; y=1 y2=1; redraw "$@"' WINCH
|
||||||
|
|
||||||
|
y=1 y2=1
|
||||||
|
redraw "$@"
|
||||||
|
|
||||||
while key=$(dd ibs=1 count=1 2>/dev/null); do
|
while key=$(dd ibs=1 count=1 2>/dev/null); do
|
||||||
case $key${esc:=0} in
|
case $key${esc:=0} in
|
||||||
k?|A2) # ARROW UP
|
k?|A2) # ARROW UP
|
||||||
[ "$y" -gt 1 ] && {
|
case $y in
|
||||||
y=$((y - 1))
|
-*|0|1) ;;
|
||||||
|
|
||||||
print_line "$((y + 1))" "$@"
|
*)
|
||||||
|
y=$((y - 1))
|
||||||
|
|
||||||
if [ "$y2" -eq 1 ]; then
|
print_line "$((y + 1))" "$@"
|
||||||
printf '\e[L'
|
|
||||||
else
|
|
||||||
printf '\e[A'
|
|
||||||
y2=$((y2 > 1 ? y2 - 1 : 1))
|
|
||||||
fi
|
|
||||||
|
|
||||||
print_line "$y" "$@"
|
case $y2 in
|
||||||
|
1)
|
||||||
|
printf '\e[L'
|
||||||
|
;;
|
||||||
|
|
||||||
status_line "$PWD ($y/$#)"
|
*)
|
||||||
}
|
printf '\e[A'
|
||||||
|
y2=$((y2 > 1 ? y2 - 1 : 1))
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
print_line "$y" "$@"
|
||||||
|
|
||||||
|
status_line "$PWD ($y/$#)"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
;;
|
;;
|
||||||
|
|
||||||
j?|B2) # ARROW DOWN
|
j?|B2) # ARROW DOWN
|
||||||
[ "$y" -lt "$#" ] && {
|
case $((y - $#)) in
|
||||||
y=$((y + 1))
|
-*)
|
||||||
y2=$((y2 + 1 < bottom ? y2 + 1 : bottom))
|
y=$((y + 1))
|
||||||
|
y2=$((y2 + 1 < bottom ? y2 + 1 : bottom))
|
||||||
|
|
||||||
print_line "$((y - 1))" "$@"
|
print_line "$((y - 1))" "$@"
|
||||||
printf '\n'
|
printf '\n'
|
||||||
print_line "$y" "$@"
|
print_line "$y" "$@"
|
||||||
|
|
||||||
status_line "$PWD ($y/$#)"
|
status_line "$PWD ($y/$#)"
|
||||||
}
|
;;
|
||||||
|
esac
|
||||||
;;
|
;;
|
||||||
|
|
||||||
l?|C2) # ARROW RIGHT
|
l?|C2) # ARROW RIGHT
|
||||||
|
|||||||
Reference in new issue
Block a user