From debfad3234119663b09f6a33f829f59d6c95e9bb Mon Sep 17 00:00:00 2001 From: Flemming Madsen Date: Fri, 8 Sep 2017 01:11:00 +0200 Subject: [PATCH] More robust cursor getter. Quit tampering with the PATH --- bin/qfc.sh | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/bin/qfc.sh b/bin/qfc.sh index ac9cce3..762e2bc 100755 --- a/bin/qfc.sh +++ b/bin/qfc.sh @@ -1,26 +1,18 @@ +#!/bin/bash # default key bindings complete_shortcut="${qfc_complete_SHORTCUT:-\C-f}" function get_cursor_position(){ - # based on a script from http://invisible-island.net/xterm/xterm.faq.html - exec < /dev/tty - oldstty=$(stty -g) - stty raw -echo min 0 - # on my system, the following line can be replaced by the line below it - echo -en "\033[6n" > /dev/tty - # tput u7 > /dev/tty # when TERM=xterm (and relatives) - IFS=';' read -r -d R row col - stty $oldstty - # change from one-based to zero based so they work with: tput cup $row $col - row=$((${row:2} - 1)) # strip off the esc-[ - col=$((${col} - 1)) - echo "$row $col" + # WAS: based on a script from http://invisible-island.net/xterm/xterm.faq.html + # NOW: the more elegant: https://unix.stackexchange.com/questions/88296/get-vertical-cursor-position/183121#183121 + local CURPOS + read -sdR -p $'\E[6n' CURPOS + CURPOS=${CURPOS#*[} # Strip decoration characters [ + local row=${CURPOS%;*} + local col=${CURPOS#*;} + echo $((row - 1)) $((col - 1)) } -if [[ -d ~/.qfc/ ]]; then - export PATH=~/.qfc/bin:"${PATH}" -fi - if [[ -n "$ZSH_VERSION" ]]; then # zshell function qfc_complete { @@ -43,7 +35,7 @@ if [[ -n "$ZSH_VERSION" ]]; then # instruct qfc to store the result (completion path) into a temporary file tmp_file=$(mktemp -t qfc.XXXXXXX) -