Last active
September 24, 2019 11:15
-
-
Save sareiodata/332e394f397ab5b950e5e5f44a61fc3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Version: 2.0 | |
# Release: November 24, 2017 | |
# Based on https://github.com/leehblue/texpander/ | |
# Get window id, pass to getwindow pid to output the pid of current window | |
pid=$(xdotool getwindowfocus getwindowpid) | |
# Store text name of process based on pid of current window | |
proc_name=$(cat /proc/$pid/comm) | |
# If ~/.texpander directory does not exist, create it | |
if [ ! -d ${HOME}/kb ]; then | |
mkdir ${HOME}/kb | |
fi | |
# Store base directory path, expand complete path using HOME environemtn variable | |
base_dir=$(realpath "${HOME}/kb") | |
name=$( zenity --file-selection --title=Texpander --filename=${base_dir}/ --file-filter="*.txt") | |
if [ -e "${name}" ] | |
then | |
# Preserve the current value of the clipboard | |
clipboard=$(xsel -b -o) | |
# Put text in primary buffer for Shift+Insert pasting | |
echo -n "$(cat "$name")" | xsel -p -i | |
# Put text in clipboard selection for apps like Firefox that | |
# insist on using the clipboard for all pasting | |
echo -n "$(cat "$name")" | xsel -b -i | |
# Paste text into current active window | |
sleep 0.3 | |
xdotool key shift+Insert | |
# If you're having trouble pasting into apps, use xdotool | |
# to type into the app instead. This is a little bit slower | |
# but may work better with some applications. | |
# | |
# Make xdotool type RETURN instead of LINEFEED characters | |
# otherwise some apps like Gmail in Firefox won't recognize | |
# newline characters. | |
# | |
# To use this, comment out line #32 (xdotool key shift+Insert) | |
# and uncomment the line below. | |
#xdotool type -- "$(xsel -bo | tr \\n \\r | sed s/\\r*\$//)" | |
# Restore the original value of the clipboard | |
sleep 0.5 | |
echo $clipboard | xsel -b -i | |
else | |
zenity --error --text="Abbreviation not found:\n${name}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment