|
|
@ -1,53 +1,44 @@ |
|
|
|
#!/usr/bin/env sh |
|
|
|
#!/bin/sh |
|
|
|
|
|
|
|
|
|
|
|
# This spell reveals the x and y coordinates of the cursor in the terminal window. |
|
|
|
# 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 |
|
|
|
# Define the function to calculate the position of the cursor |
|
|
|
fathom_cursor() { |
|
|
|
fathom_cursor() { |
|
|
|
local position |
|
|
|
x=false |
|
|
|
local x=false |
|
|
|
y=false |
|
|
|
local y=false |
|
|
|
verbose=false |
|
|
|
local verbose=false |
|
|
|
for arg; do |
|
|
|
while getopts 'vxy' flag; do |
|
|
|
case "$arg" in |
|
|
|
case "${flag}" in |
|
|
|
--verbose|-v) verbose=true ;; |
|
|
|
--verbose|v) verbose=true ;; |
|
|
|
-x) x=true ;; |
|
|
|
x) x=true ;; |
|
|
|
-y) y=true ;; |
|
|
|
y) y=true ;; |
|
|
|
|
|
|
|
esac |
|
|
|
esac |
|
|
|
done |
|
|
|
done |
|
|
|
|
|
|
|
|
|
|
|
# Get the position of the cursor |
|
|
|
# Get the position of the cursor |
|
|
|
stty -echo |
|
|
|
stty -echo |
|
|
|
printf "\033[6n" |
|
|
|
printf "\033[6n" |
|
|
|
while IFS=';' read -r -d R ROW COL; do |
|
|
|
IFS=';' read -r -d R ROW COL |
|
|
|
break |
|
|
|
|
|
|
|
done |
|
|
|
|
|
|
|
stty echo |
|
|
|
stty echo |
|
|
|
position=$(printf "%s;%s" "${COL%%R*}" "${ROW#*[}") |
|
|
|
position=$(printf "%s;%s" "${ROW#*[}" "${COL%%R*}") |
|
|
|
|
|
|
|
|
|
|
|
if [ $x = true ] && [ $y = true ]; then |
|
|
|
if $x && $y; then |
|
|
|
if [ $verbose = true ]; then |
|
|
|
if $verbose; then |
|
|
|
printf "X: %s\n" "${position##*;}" |
|
|
|
printf "X: %s\n" "${position%%;*}" |
|
|
|
printf "Y: %s\n" "${position%%;*}" |
|
|
|
printf "Y: %s\n" "${position##*;}" |
|
|
|
else |
|
|
|
else |
|
|
|
printf "%s\n" "${position##*;}" |
|
|
|
|
|
|
|
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##*;}" |
|
|
|
printf "%s\n" "${position##*;}" |
|
|
|
elif [ $y = true ]; then |
|
|
|
|
|
|
|
if [ $verbose = true ]; then |
|
|
|
|
|
|
|
printf "Y: " |
|
|
|
|
|
|
|
fi |
|
|
|
fi |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
if $x; then |
|
|
|
|
|
|
|
[ "$verbose" = true ] && printf "X: " |
|
|
|
printf "%s\n" "${position%%;*}" |
|
|
|
printf "%s\n" "${position%%;*}" |
|
|
|
|
|
|
|
elif $y; then |
|
|
|
|
|
|
|
[ "$verbose" = true ] && printf "Y: " |
|
|
|
|
|
|
|
printf "%s\n" "${position##*;}" |
|
|
|
else |
|
|
|
else |
|
|
|
if [ $verbose = true ]; then |
|
|
|
[ "$verbose" = true ] && printf "Position: " |
|
|
|
printf "Position: " |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
printf "%s\n" "$position" |
|
|
|
printf "%s\n" "$position" |
|
|
|
fi |
|
|
|
fi |
|
|
|
fi |
|
|
|
fi |
|
|
|