Detect vim to handle cursor position

This commit is contained in:
BarbUk 2020-02-09 10:13:14 +04:00
parent 770da804d3
commit 4439676c5a

23
snippy
View File

@ -80,11 +80,25 @@ bashdown_simple() {
# Detect if focused app is a terminal or a gui # Detect if focused app is a terminal or a gui
is_gui() { is_gui() {
name="$(xprop -id "$(xdotool getwindowfocus)" WM_CLASS | cut -d'"' -f2 | tr '[:upper:]' '[:lower:]')" class="$(xprop -id "$(xdotool getwindowfocus)" WM_CLASS | cut -d'"' -f2 | tr '[:upper:]' '[:lower:]')"
[[ "$name" =~ term|tilda|kitty|alacritty ]] && return 1 # Return false if the class if a term
if [[ "$class" =~ term|tilda|kitty|alacritty ]]; then
return 1
fi
return 0 return 0
} }
# Detect vim
is_vim() {
name="$(xprop -id "$(xdotool getwindowfocus)" WM_NAME | cut -d'"' -f2)"
# vim with `set title` set the term title with:
# document - VIM
if [[ "${name:(-3)}" == VIM ]]; then
return 0
fi
return 1
}
# Find the index of a string in a string # Find the index of a string in a string
strindex() { strindex() {
x="${1%%$2*}" x="${1%%$2*}"
@ -214,12 +228,15 @@ run() {
# Paste into the current application. # Paste into the current application.
if is_gui; then if is_gui; then
# We need a little pause to handle the time to focus on the window # We need a little pause to handle the time to focus on the window
sleep 0.05 sleep 0.225
wait wait
${GUIPASTE} ${GUIPASTE}
move_cursor "Up" $cursor_line_position move_cursor "Up" $cursor_line_position
else else
${CLIPASTE} ${CLIPASTE}
if is_vim; then
move_cursor "Up" $cursor_line_position
fi
fi fi
move_cursor "Left" $cursor_position move_cursor "Left" $cursor_position