Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions bin/qfc.sh
Original file line number Diff line number Diff line change
@@ -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 <ESC>[
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 {
Expand All @@ -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)
</dev/tty qfc --search="$word" --stdout="$tmp_file"
</dev/tty $HOME/.qfc/bin/qfc --search="$word" --stdout="$tmp_file"
result=$(<$tmp_file)
rm -f $tmp_file

Expand Down Expand Up @@ -91,7 +83,7 @@ elif [[ -n "$BASH" ]]; then
word=${word##* }

tmp_file=$(mktemp -t qfc.XXXXXXX)
</dev/tty qfc --search="$word" --stdout="$tmp_file"
</dev/tty $HOME/.qfc/bin/qfc --search="$word" --stdout="$tmp_file"
result=$(<$tmp_file)
rm -f $tmp_file

Expand Down