mirror of
https://github.com/notwa/rc
synced 2024-11-05 13:19:03 -08:00
more work on glug; new g
and G
commands
This commit is contained in:
parent
3152639dcd
commit
a7ff1eb658
1 changed files with 23 additions and 5 deletions
28
sh/glug
28
sh/glug
|
@ -45,6 +45,7 @@ glug() ( # note the subshell syntax. this allows us to abuse globals like crazy.
|
||||||
err=
|
err=
|
||||||
|
|
||||||
alt_on() {
|
alt_on() {
|
||||||
|
# globals: $alt
|
||||||
printf '\033[?1049h' # alt screen on (smcup)
|
printf '\033[?1049h' # alt screen on (smcup)
|
||||||
alt=1
|
alt=1
|
||||||
printf '\033[?1h\033=' # no idea but less does it so it must be important (smkx)
|
printf '\033[?1h\033=' # no idea but less does it so it must be important (smkx)
|
||||||
|
@ -53,24 +54,28 @@ glug() ( # note the subshell syntax. this allows us to abuse globals like crazy.
|
||||||
}
|
}
|
||||||
|
|
||||||
alt_off() {
|
alt_off() {
|
||||||
|
# globals: $alt
|
||||||
printf '\r' # move cursor to start of line (carriage return)
|
printf '\r' # move cursor to start of line (carriage return)
|
||||||
#printf '\033[K' # erase everything before the cursor (el)
|
#printf '\033[K' # erase everything after the cursor (el)
|
||||||
printf '\033[?1l\033>' # no idea but less does it so it must be important (rmkx)
|
printf '\033[?1l\033>' # no idea but less does it so it must be important (rmkx)
|
||||||
printf '\033[?1049l' # alt screen off (rmcup)
|
printf '\033[?1049l' # alt screen off (rmcup)
|
||||||
alt=0
|
alt=0
|
||||||
}
|
}
|
||||||
|
|
||||||
glug_enter() {
|
glug_enter() {
|
||||||
|
# globals: $alt
|
||||||
[ $alt = 1 ] || alt_on
|
[ $alt = 1 ] || alt_on
|
||||||
}
|
}
|
||||||
|
|
||||||
glug_exit() {
|
glug_exit() {
|
||||||
|
# globals: $alt, $err, $ret
|
||||||
[ $alt = 0 ] || alt_off
|
[ $alt = 0 ] || alt_off
|
||||||
[ -z "$err" ] || printf '%s\n' "$err" >&2
|
[ -z "$err" ] || printf '%s\n' "$err" >&2
|
||||||
exit $ret
|
exit $ret
|
||||||
}
|
}
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
|
# globals: $ret, $err
|
||||||
ret=$?
|
ret=$?
|
||||||
err="$@"
|
err="$@"
|
||||||
[ $? = 0 ] && exit 1 || exit $?
|
[ $? = 0 ] && exit 1 || exit $?
|
||||||
|
@ -86,13 +91,14 @@ glug() ( # note the subshell syntax. this allows us to abuse globals like crazy.
|
||||||
} </dev/tty # ensure this interacts with a terminal instead of a pipe
|
} </dev/tty # ensure this interacts with a terminal instead of a pipe
|
||||||
|
|
||||||
escape_message() {
|
escape_message() {
|
||||||
|
# arguments: $message
|
||||||
_msg=
|
_msg=
|
||||||
while _seg="${message%%\'*}"; [ "$_seg" != "$message" ]; do
|
while _seg="${message%%\'*}"; [ "$_seg" != "$message" ]; do
|
||||||
_msg="$_msg$_seg'\''"
|
_msg="$_msg$_seg'\''"
|
||||||
message="${message#*\'}"
|
message="${message#*\'}"
|
||||||
done
|
done
|
||||||
message="$_msg$message"
|
message="$_msg$message"
|
||||||
unset _msg _new _seg
|
unset _msg _seg
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_logs() {
|
parse_logs() {
|
||||||
|
@ -116,6 +122,7 @@ glug() ( # note the subshell syntax. this allows us to abuse globals like crazy.
|
||||||
eval "choice_$choices=$commit"
|
eval "choice_$choices=$commit"
|
||||||
eval "commit_$commit='$message'"
|
eval "commit_$commit='$message'"
|
||||||
done
|
done
|
||||||
|
unset _line _next
|
||||||
}
|
}
|
||||||
|
|
||||||
colorize_pathy() {
|
colorize_pathy() {
|
||||||
|
@ -143,6 +150,7 @@ glug() ( # note the subshell syntax. this allows us to abuse globals like crazy.
|
||||||
fi
|
fi
|
||||||
diffy="${diffy#$_seg}"
|
diffy="${diffy#$_seg}"
|
||||||
done
|
done
|
||||||
|
unset _seg
|
||||||
}
|
}
|
||||||
|
|
||||||
colorize_summary() {
|
colorize_summary() {
|
||||||
|
@ -173,6 +181,7 @@ glug() ( # note the subshell syntax. this allows us to abuse globals like crazy.
|
||||||
fi
|
fi
|
||||||
gds="${gds#$_seg}"
|
gds="${gds#$_seg}"
|
||||||
done
|
done
|
||||||
|
unset _color _ins _seg
|
||||||
}
|
}
|
||||||
|
|
||||||
format_stats() {
|
format_stats() {
|
||||||
|
@ -195,6 +204,7 @@ glug() ( # note the subshell syntax. this allows us to abuse globals like crazy.
|
||||||
colorize_summary
|
colorize_summary
|
||||||
printf '\n'
|
printf '\n'
|
||||||
: $((linesleft-=1))
|
: $((linesleft-=1))
|
||||||
|
unset _line
|
||||||
}
|
}
|
||||||
|
|
||||||
present_choices() {
|
present_choices() {
|
||||||
|
@ -242,6 +252,8 @@ glug() ( # note the subshell syntax. this allows us to abuse globals like crazy.
|
||||||
[ $linesleft -ge 2 ] || break
|
[ $linesleft -ge 2 ] || break
|
||||||
done
|
done
|
||||||
if [ $linesleft -ge 1 ]; then
|
if [ $linesleft -ge 1 ]; then
|
||||||
|
printf '\033[%s;0H' $LINES
|
||||||
|
linesleft=1
|
||||||
printf ' \033[33m(\033[97m%s\033[33m/\033[97m%s\033[33m)\033[m ' "$selection" "$choices"
|
printf ' \033[33m(\033[97m%s\033[33m/\033[97m%s\033[33m)\033[m ' "$selection" "$choices"
|
||||||
: $((linesleft-=1))
|
: $((linesleft-=1))
|
||||||
fi
|
fi
|
||||||
|
@ -253,7 +265,6 @@ glug() ( # note the subshell syntax. this allows us to abuse globals like crazy.
|
||||||
# TODO: reset button that checks LINES and COLUMNS again.
|
# TODO: reset button that checks LINES and COLUMNS again.
|
||||||
printf '\0338' # restore cursor to prompt position (rc)
|
printf '\0338' # restore cursor to prompt position (rc)
|
||||||
input="$(read_byte)" || return
|
input="$(read_byte)" || return
|
||||||
printf '\033[K' # TODO: unnecessary?
|
|
||||||
if [ "${input%_}" = "$input" ]; then
|
if [ "${input%_}" = "$input" ]; then
|
||||||
# no magic underscore, something went wrong.
|
# no magic underscore, something went wrong.
|
||||||
return 1
|
return 1
|
||||||
|
@ -267,13 +278,19 @@ glug() ( # note the subshell syntax. this allows us to abuse globals like crazy.
|
||||||
input=" ${input#$nl}"
|
input=" ${input#$nl}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${input#[! jkq]}" != "$input" ]; then
|
if [ "${input#[! gGjkq]}" != "$input" ]; then
|
||||||
_seg="${input%%[ jkq]*}"
|
_seg="${input%%[ gGjkq]*}"
|
||||||
elif [ "${input# }" != "$input" ]; then
|
elif [ "${input# }" != "$input" ]; then
|
||||||
_seg=' '
|
_seg=' '
|
||||||
alt_off
|
alt_off
|
||||||
git diff "$commit~" "$commit" || exit
|
git diff "$commit~" "$commit" || exit
|
||||||
alt_on
|
alt_on
|
||||||
|
elif [ "${input#g}" != "$input" ]; then
|
||||||
|
_seg=g
|
||||||
|
selection=1
|
||||||
|
elif [ "${input#G}" != "$input" ]; then
|
||||||
|
_seg=G
|
||||||
|
selection=$choices
|
||||||
elif [ "${input#j}" != "$input" ]; then
|
elif [ "${input#j}" != "$input" ]; then
|
||||||
_seg=j
|
_seg=j
|
||||||
[ $((selection+=1)) -le $choices ] || selection=$choices
|
[ $((selection+=1)) -le $choices ] || selection=$choices
|
||||||
|
@ -288,6 +305,7 @@ glug() ( # note the subshell syntax. this allows us to abuse globals like crazy.
|
||||||
fi
|
fi
|
||||||
input="${input#$_seg}"
|
input="${input#$_seg}"
|
||||||
done
|
done
|
||||||
|
unset _seg
|
||||||
}
|
}
|
||||||
|
|
||||||
trap glug_exit INT EXIT && glug_enter
|
trap glug_exit INT EXIT && glug_enter
|
||||||
|
|
Loading…
Reference in a new issue