tmux-thumbs/tmux-thumbs.sh

55 lines
1.4 KiB
Bash
Raw Normal View History

2019-02-04 21:40:45 +00:00
#!/usr/bin/env bash
2019-03-06 17:04:05 +00:00
source ~/.bash_profile
2019-03-20 23:31:28 +00:00
function boolean {
2019-03-28 13:02:15 +00:00
VALUE=$(tmux show -vg @thumbs-$1 2> /dev/null)
2019-03-20 23:31:28 +00:00
if [[ "${VALUE}" == "1" ]]; then
echo "--$1"
fi
}
function option {
2019-03-28 13:02:15 +00:00
VALUE=$(tmux show -vg @thumbs-$1 2> /dev/null)
2019-03-20 23:31:28 +00:00
if [[ ${VALUE} ]]; then
echo "--$1 ${VALUE}"
fi
}
function multi {
VALUES=""
2019-03-28 13:02:15 +00:00
while read -r ITEM_KEY; do
VALUE=$(tmux show -vg $ITEM_KEY 2> /dev/null)
2019-03-20 23:31:28 +00:00
VALUES="${VALUES} --$1 ${VALUE}"
2019-03-28 13:02:15 +00:00
done < <(tmux show -g 2> /dev/null | grep thumbs-$1- | cut -d' ' -f1)
2019-03-20 23:31:28 +00:00
echo ${VALUES}
}
PARAMS=()
PARAMS[0]=$(boolean reverse)
PARAMS[1]=$(boolean unique)
PARAMS[2]=$(option alphabet)
PARAMS[3]=$(option position)
PARAMS[4]=$(option fg-color)
PARAMS[5]=$(option bg-color)
PARAMS[6]=$(option hint-bg-color)
PARAMS[7]=$(option hint-fg-color)
PARAMS[8]=$(option select-fg-color)
PARAMS[9]=$(option command)
PARAMS[10]=$(option upcase-command)
PARAMS[11]=$(multi regexp)
PARAMS[12]=$(boolean contrast)
2019-03-09 22:39:16 +00:00
2019-03-10 09:45:22 +00:00
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TARGET_RELEASE="/target/release/"
2019-03-05 08:10:41 +00:00
CURRENT_PANE_ID=$(tmux list-panes -F "#{pane_id}:#{?pane_active,active,nope}" | grep active | cut -d: -f1)
2019-03-20 23:31:28 +00:00
COMMAND="tmux-thumbs ${PARAMS[*]} --tmux-pane ${CURRENT_PANE_ID}"
NEW_ID=$(tmux new-window -P -d -n "[thumbs]" ${CURRENT_DIR}${TARGET_RELEASE}${COMMAND})
2019-03-06 15:13:49 +00:00
NEW_PANE_ID=$(tmux list-panes -a | grep ${NEW_ID} | grep --color=never -o '%[0-9]\+')
2019-03-05 08:10:41 +00:00
2019-03-06 15:13:49 +00:00
tmux swap-pane -d -s ${CURRENT_PANE_ID} -t ${NEW_PANE_ID}