Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #######################################################################################
- # Q: What's this rofi-autokey?
- # A: Just in case 'autokey-git' shouldn't work, this little bash script
- # lets you search your autokey's dataset by filename and contents via rofi,
- # obtaining the wanted item in clipboard and/or in stdout.
- # Can be invoked by its name or via a sxhkd shortcut.
- #######################################################################################
- # Requires : autokey, rofi, xdotool, xclip, optional sxhkd, mc
- #
- # 'autokey' URL : https://github.com/autokey/autokey
- # 'rofi' URL : https://github.com/DaveDavenport/rofi
- # 'xdotool' URL : https://www.semicomplete.com/projects/xdotool/
- # 'xclip' URL : https://github.com/astrand/xclip
- # 'sxhkd' URL : https://github.com/baskerville/sxhkd
- # 'mc' URL : https://midnight-commander.org
- #######################################################################################
- # Creates :A working directory 'akeys' containing a copy of the .txt files
- # used by autokey, located in ~/.local/share/aKeys
- ########################################################################################
- # Usage: rofi-autokey
- # Args: nothing, or '-', 'f', 'upd', 'sx', 'ANYTHING ELSE' (see function Usage below)
- ########################################################################################
- # Auth='Piero Strada'
- # Rel='01 set 2021, 15:36:49, CET'
- # Upd='07 set 2022, 12:00:49, CET'
- # Ver='1.0.0'
- # mVer='5'
- #######################################################################################
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see [[http://www.gnu.org/licenses/]].
- #######################################################################################
- KDIR="$HOME/.local/share/aKeys" #Working directory
- mFM="mc" #Chosen filemanager
- Usage(){
- echo "Usage:"
- echo "[super + k] -> '$(basename "$0")': get the shortcut content in clipboard;"
- echo "[super + shift + k] -> '$(basename "$0") -': Ditto, AND get it in stdout via xdotool."
- echo
- echo "'$(basename "$0") f': Opens '$mFM' on the 2 datasets;"
- echo "'$(basename "$0") upd': Update 'aKeys' dataset;"
- echo "'$(basename "$0") sx': Get the code for sxhkd;"
- echo "'$(basename "$0") anything-else': This help."
- }
- akFiles(){
- $mFM "$KDIR" $HOME/.config/autokey/data/My\ Phrases/
- }
- setSX(){
- echo "Copy this output, and paste it inside your ~/.config/sxhkd/sxhkdrc file:"
- echo "(Indentation matters.)"
- echo
- printf "#rofi-autokey\n"
- printf "super + k\n"
- printf "\trofi-autokey\n"
- printf "super + shift + k\n"
- printf "\trofi-autokey -\n"
- echo
- }
- setKeys(){
- #echo "Updating dataset..." >/dev/stderr
- rm -rf "$KDIR" 2>/dev/null
- mkdir "$KDIR"
- cp $HOME/.config/autokey/data/My\ Phrases/*.txt "$KDIR"
- #echo "Dataset updated." >/dev/stderr
- }
- main(){
- aksel=`grep -e "" $KDIR/*.txt | cut -d'/' -f7- | rofi -dmenu -p "Autokeys" | cut -d':' -f1`
- [[ "$aksel" = "" ]] && exit
- if [[ -f $KDIR/$aksel ]]; then
- cat $KDIR/$aksel | xclip -sel clip || $mFM $KDIR
- notify-send -u low "$(echo $aksel|cut -d '.' -f 1) : " "in clipboard"
- [ "$1" = '-' ] && xdotool type "`cat $KDIR/$aksel`"
- else
- notify-send -u critical "Error:" "$KDIR/$aksel"
- fi
- }
- case "$1" in
- '');;
- '-');;
- 'f')
- akFiles
- exit
- ;;
- 'upd')
- setKeys
- ;;
- 'sx')
- setSX
- exit
- ;;
- *)
- Usage
- exit
- esac
- #Comment the line below to update 'aKeys' dataset on demand only (rofi-autokey upd)
- setKeys
- main "$1"
Advertisement
Add Comment
Please, Sign In to add comment