mirror of
https://github.com/FliegendeWurst/tmux-thumbs.git
synced 2024-11-22 21:05:00 +00:00
Merge pull request #15 from isundaylee/args-fix
Fixes passing options with spaces in the value
This commit is contained in:
commit
df0b616f29
@ -2,53 +2,55 @@
|
|||||||
|
|
||||||
source ~/.bash_profile
|
source ~/.bash_profile
|
||||||
|
|
||||||
function boolean {
|
PARAMS=()
|
||||||
|
|
||||||
|
function add-boolean-param {
|
||||||
VALUE=$(tmux show -vg @thumbs-$1 2> /dev/null)
|
VALUE=$(tmux show -vg @thumbs-$1 2> /dev/null)
|
||||||
|
|
||||||
if [[ "${VALUE}" == "1" ]]; then
|
if [[ "${VALUE}" == "1" ]]; then
|
||||||
echo "--$1"
|
PARAMS+=("--$1")
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function option {
|
function add-option-param {
|
||||||
VALUE=$(tmux show -vg @thumbs-$1 2> /dev/null)
|
VALUE=$(tmux show -vg @thumbs-$1 2> /dev/null)
|
||||||
|
|
||||||
if [[ ${VALUE} ]]; then
|
if [[ ${VALUE} ]]; then
|
||||||
echo "--$1 ${VALUE}"
|
PARAMS+=("--$1=${VALUE}")
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function multi {
|
function add-multi-param {
|
||||||
VALUES=""
|
|
||||||
|
|
||||||
while read -r ITEM_KEY; do
|
while read -r ITEM_KEY; do
|
||||||
VALUE=$(tmux show -vg $ITEM_KEY 2> /dev/null)
|
VALUE=$(tmux show -vg $ITEM_KEY 2> /dev/null)
|
||||||
VALUES="${VALUES} --$1 ${VALUE}"
|
PARAMS+=("--$1=${VALUE}")
|
||||||
done < <(tmux show -g 2> /dev/null | grep thumbs-$1- | cut -d' ' -f1)
|
done < <(tmux show -g 2> /dev/null | grep thumbs-$1- | cut -d' ' -f1)
|
||||||
|
|
||||||
echo ${VALUES}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PARAMS=()
|
add-boolean-param "reverse"
|
||||||
PARAMS[0]=$(boolean reverse)
|
add-boolean-param "unique"
|
||||||
PARAMS[1]=$(boolean unique)
|
add-option-param "alphabet"
|
||||||
PARAMS[2]=$(option alphabet)
|
add-option-param "position"
|
||||||
PARAMS[3]=$(option position)
|
add-option-param "fg-color"
|
||||||
PARAMS[4]=$(option fg-color)
|
add-option-param "bg-color"
|
||||||
PARAMS[5]=$(option bg-color)
|
add-option-param "hint-bg-color"
|
||||||
PARAMS[6]=$(option hint-bg-color)
|
add-option-param "hint-fg-color"
|
||||||
PARAMS[7]=$(option hint-fg-color)
|
add-option-param "select-fg-color"
|
||||||
PARAMS[8]=$(option select-fg-color)
|
add-option-param "command"
|
||||||
PARAMS[9]=$(option command)
|
add-option-param "upcase-command"
|
||||||
PARAMS[10]=$(option upcase-command)
|
add-multi-param "regexp"
|
||||||
PARAMS[11]=$(multi regexp)
|
add-boolean-param "contrast"
|
||||||
PARAMS[12]=$(boolean contrast)
|
|
||||||
|
# Remove empty arguments from PARAMS.
|
||||||
|
# Otherwise, they would choke up tmux-thumbs when passed to it.
|
||||||
|
for i in "${!PARAMS[@]}"; do
|
||||||
|
[ -n "${PARAMS[$i]}" ] || unset "PARAMS[$i]"
|
||||||
|
done
|
||||||
|
|
||||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
TARGET_RELEASE="/target/release/"
|
TARGET_RELEASE="/target/release/"
|
||||||
CURRENT_PANE_ID=$(tmux list-panes -F "#{pane_id}:#{?pane_active,active,nope}" | grep active | cut -d: -f1)
|
CURRENT_PANE_ID=$(tmux list-panes -F "#{pane_id}:#{?pane_active,active,nope}" | grep active | cut -d: -f1)
|
||||||
COMMAND="tmux-thumbs ${PARAMS[*]} --tmux-pane ${CURRENT_PANE_ID}"
|
NEW_ID=$(tmux new-window -P -d -n "[thumbs]" ${CURRENT_DIR}${TARGET_RELEASE}tmux-thumbs "${PARAMS[@]}" "--tmux-pane=${CURRENT_PANE_ID}")
|
||||||
NEW_ID=$(tmux new-window -P -d -n "[thumbs]" ${CURRENT_DIR}${TARGET_RELEASE}${COMMAND})
|
|
||||||
NEW_PANE_ID=$(tmux list-panes -a | grep ${NEW_ID} | grep --color=never -o '%[0-9]\+')
|
NEW_PANE_ID=$(tmux list-panes -a | grep ${NEW_ID} | grep --color=never -o '%[0-9]\+')
|
||||||
|
|
||||||
tmux swap-pane -d -s ${CURRENT_PANE_ID} -t ${NEW_PANE_ID}
|
tmux swap-pane -d -s ${CURRENT_PANE_ID} -t ${NEW_PANE_ID}
|
||||||
|
Loading…
Reference in New Issue
Block a user