You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.3 KiB
51 lines
1.3 KiB
#!/usr/bin/env sh |
|
|
|
# This spell reveals the x and y coordinates of the cursor in the terminal window. |
|
|
|
# Define the function to calculate the position of the cursor |
|
fathom_cursor() { |
|
position="" |
|
x=false |
|
y=false |
|
verbose=false |
|
while getopts 'vxy' flag; do |
|
case "${flag}" in |
|
--verbose|v) verbose=true ;; |
|
x) x=true ;; |
|
y) y=true ;; |
|
esac |
|
done |
|
|
|
# Get the position of the cursor |
|
position=$(IFS=';' read -sdR -p $'\E[6n' ROW COL; printf "%s;%s" "${ROW#*[}" "$COL") |
|
|
|
if [ "$x" = true ] && [ "$y" = true ]; then |
|
if [ "$verbose" = true ]; then |
|
printf "X: %s\n" "${position##*;}" |
|
printf "Y: %s\n" "${position%%;*}" |
|
else |
|
printf "%s\n" "${position##*;}" |
|
printf "%s\n" "${position%%;*}" |
|
fi |
|
else |
|
if [ "$x" = true ]; then |
|
if [ "$verbose" = true ]; then |
|
printf "X: " |
|
fi |
|
printf "%s\n" "${position##*;}" |
|
elif [ "$y" = true ]; then |
|
if [ "$verbose" = true ]; then |
|
printf "Y: " |
|
fi |
|
printf "%s\n" "${position%%;*}" |
|
else |
|
if [ "$verbose" = true ]; then |
|
printf "Position: " |
|
fi |
|
printf "%s\n" "$position" |
|
fi |
|
fi |
|
} |
|
|
|
# Call the function |
|
fathom_cursor "$@" |