WIPWORKS
This commit is contained in:
parent
fc4fea2721
commit
79d1eee3b6
|
@ -1,31 +1,14 @@
|
|||
#!/bin/bash
|
||||
clear
|
||||
|
||||
#TODO move this out of here!
|
||||
current_pane_id=$1
|
||||
fingers_pane_id=$2
|
||||
|
||||
ALPHABET=asdfqwertjkluiop
|
||||
ALPHABET_SIZE=${#ALPHABET}
|
||||
HINTS=(aa as ad af aq aw ae ar at aj ak al au ai ao ap sa ss sd sf sq sw se sr st sj sk sl su si so sp da ds dd df dq dw de dr dt dj dk dl du di do dp fa fs fd ff fq fw fe fr ft fj fk fl fu fi fo fp qa qs qd qf qq qw qe qr qt qj qk ql qu qi qo qp wa ws wd wf wq ww we wr wt wj e r t j k l u i o p)
|
||||
|
||||
function ceiling() {
|
||||
local digits=$1
|
||||
|
||||
if [[ ! $digits =~ ^[1-9]\.0+$ ]]; then
|
||||
digits=`echo "$digits + 1" | bc`
|
||||
fi
|
||||
|
||||
echo $digits | grep -o ^[0-9]
|
||||
}
|
||||
|
||||
function digits_needed() {
|
||||
ceiling `echo "l($1) / l(16)" | bc -l`
|
||||
}
|
||||
|
||||
function translate() {
|
||||
echo $1 | tr -s 0123456789abcdef $ALPHABET
|
||||
}
|
||||
|
||||
function to_hex() {
|
||||
echo "obase=16; $1" | bc | tr A-F a-f
|
||||
}
|
||||
|
||||
function get_hint() {
|
||||
echo ${HINTS[$1]}
|
||||
}
|
||||
|
@ -34,39 +17,64 @@ function fancy() {
|
|||
printf "\033[1;33m$1\033[0m"
|
||||
}
|
||||
|
||||
PATTERNS=
|
||||
|
||||
lines=''
|
||||
while read -r line
|
||||
do
|
||||
lines+="$line\n"
|
||||
done < "${1:-/dev/stdin}"
|
||||
done < /dev/stdin
|
||||
|
||||
matches=`echo -e $lines | (grep -oniE "([0-9a-f]{7,40})" 2> /dev/null) | sort -u`
|
||||
matches=`echo -e $lines | (grep -oniE "((^|^\.|[[:space:]]|[[:space:]]\.|[[:space:]]\.\.|^\.\.)[[:alnum:]~_-]*/[][[:alnum:]_.#$%&+=/@-]*)|([[:digit:]]+)|([0-9a-f]{7,40})" 2> /dev/null) | sort -u`
|
||||
match_count=`echo "$matches" | wc -l`
|
||||
|
||||
output="$lines"
|
||||
i=0
|
||||
|
||||
match_lookup=''
|
||||
OLDIFS=$IFS
|
||||
IFS=$(echo -en "\n\b") # wtf bash?
|
||||
for match in $matches ; do
|
||||
echo "for match [$match]"
|
||||
hint=`get_hint $i`
|
||||
linenumber=`echo $match | cut -f1 -d:`
|
||||
text=`echo $match | cut -f2 -d:`
|
||||
output=`echo -e "$output" | sed -e "${linenumber}s/$text/$(fancy $text) $(fancy "[$hint]")/g"`
|
||||
output=`echo -e "$output" | sed "${linenumber}s!$text!$(fancy $text) $(fancy "[$hint]")!g"`
|
||||
match_lookup="$match_lookup\n$hint:$text"
|
||||
i=$(($i+1))
|
||||
done
|
||||
IFS=$OLDIFS
|
||||
|
||||
echo -e "$output"
|
||||
|
||||
function handle_exit() {
|
||||
tmux swap-pane -s $current_pane_id -t $fingers_pane_id
|
||||
tmux kill-pane -t $fingers_pane_id
|
||||
}
|
||||
|
||||
trap "handle_exit" EXIT
|
||||
|
||||
input=''
|
||||
while read -n 1 char
|
||||
do
|
||||
input="$input$char"
|
||||
result=`echo -e $match_lookup | grep "^$input:" | cut -f2 -d:`
|
||||
|
||||
tmux display-message "$input"
|
||||
|
||||
if [[ ! -z $result ]]; then
|
||||
echo $result | xclip -selection c
|
||||
clear
|
||||
echo "$result"
|
||||
|
||||
tmux copy-mode
|
||||
tmux send-key "H" # top of buffer
|
||||
tmux send-key "v" # start selection
|
||||
tmux send-key "$" # end of word
|
||||
tmux send-key "y" # yank
|
||||
|
||||
tmux swap-pane -s $current_pane_id -t $fingers_pane_id
|
||||
tmux kill-pane -t $fingers_pane_id
|
||||
|
||||
exit 0
|
||||
fi
|
||||
done < /dev/tty > /dev/null
|
||||
|
||||
done < /dev/tty
|
||||
|
|
|
@ -11,7 +11,7 @@ function pane_exec() {
|
|||
}
|
||||
|
||||
function init_fingers_pane() {
|
||||
local pane_id=`tmux new-window -P -d -n tmux-fingers | cut -d: -f2`
|
||||
local pane_id=`tmux new-window -P -d -n "!fingers" | cut -d: -f2`
|
||||
|
||||
echo $pane_id
|
||||
}
|
||||
|
@ -20,12 +20,18 @@ function prompt_fingers_for_pane() {
|
|||
local current_pane_id=$1
|
||||
local fingers_pane_id=`init_fingers_pane`
|
||||
local tmp_path=`mktemp --suffix "tmux-fingers"`
|
||||
wait
|
||||
|
||||
tmux capture-pane -p -t $current_pane_id > $tmp_path
|
||||
pane_exec $fingers_pane_id "cat $tmp_path | $CURRENT_DIR/fingers.sh"
|
||||
pane_exec $fingers_pane_id "cat $tmp_path | $CURRENT_DIR/fingers.sh $current_pane_id $fingers_pane_id"
|
||||
|
||||
tmux swap-pane -s $current_pane_id -t $fingers_pane_id
|
||||
|
||||
#rm $tmp_path
|
||||
|
||||
echo $fingers_pane_id
|
||||
}
|
||||
|
||||
current_pane_id=`tmux list-panes | grep active | grep -oE ^[[:digit:]]+`
|
||||
prompt_fingers_for_pane $current_pane_id
|
||||
fingers_pane_id=`prompt_fingers_for_pane $current_pane_id`
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
tmux bind-key F run-shell "tmux capture-pane -p | $CURRENT_DIR/scripts/tmux-fingers.sh"
|
||||
tmux bind -n C-f run-shell "tmux capture-pane -p | $CURRENT_DIR/scripts/tmux-fingers.sh"
|
||||
|
|
Loading…
Reference in New Issue