pierostrada

rofi-autokey

Jul 20th, 2022
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.99 KB | None | 0 0
  1. #!/bin/bash
  2. #######################################################################################
  3. #   Q:  What's this rofi-autokey?
  4. #   A:  Just in case 'autokey-git' shouldn't work, this little bash script
  5. #   lets you search your autokey's dataset by filename and contents via rofi,
  6. #   obtaining the wanted item in clipboard and/or in stdout.
  7. #   Can be invoked by its name or via a sxhkd shortcut.
  8. #######################################################################################
  9. #   Requires    : autokey, rofi, xdotool, xclip, optional sxhkd, mc
  10. #
  11. #   'autokey' URL   : https://github.com/autokey/autokey
  12. #   'rofi' URL  : https://github.com/DaveDavenport/rofi
  13. #   'xdotool' URL   : https://www.semicomplete.com/projects/xdotool/
  14. #   'xclip' URL : https://github.com/astrand/xclip
  15. #   'sxhkd' URL : https://github.com/baskerville/sxhkd
  16. #   'mc' URL    : https://midnight-commander.org
  17. #######################################################################################
  18. #   Creates     :A working directory 'akeys' containing a copy of the .txt files
  19. #   used by autokey, located in ~/.local/share/aKeys
  20. ########################################################################################
  21. #   Usage: rofi-autokey
  22. #   Args: nothing, or '-', 'f', 'upd', 'sx', 'ANYTHING ELSE' (see function Usage below)
  23. ########################################################################################
  24. #   Auth='Piero Strada'
  25. #   Rel='01 set 2021, 15:36:49, CET'
  26. #   Upd='07 set 2022, 12:00:49, CET'
  27. #   Ver='1.0.0'
  28. #   mVer='5'
  29. #######################################################################################
  30. #   This program is free software: you can redistribute it and/or modify
  31. #   it under the terms of the GNU General Public License as published by
  32. #   the Free Software Foundation, either version 3 of the License, or
  33. #   (at your option) any later version.
  34. #
  35. #   This program is distributed in the hope that it will be useful,
  36. #   but WITHOUT ANY WARRANTY; without even the implied warranty of
  37. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  38. #   GNU General Public License for more details.
  39. #
  40. #   You should have received a copy of the GNU General Public License
  41. #   along with this program.  If not, see [[http://www.gnu.org/licenses/]].
  42. #######################################################################################
  43.  
  44. KDIR="$HOME/.local/share/aKeys" #Working directory
  45. mFM="mc"            #Chosen filemanager
  46. Usage(){
  47.     echo "Usage:"
  48.     echo "[super + k] -> '$(basename "$0")': get the shortcut content in clipboard;"
  49.     echo "[super + shift + k] -> '$(basename "$0") -': Ditto, AND get it in stdout via xdotool."
  50.     echo
  51.     echo "'$(basename "$0") f': Opens '$mFM' on the 2 datasets;"
  52.     echo "'$(basename "$0") upd': Update 'aKeys' dataset;"
  53.     echo "'$(basename "$0") sx': Get the code for sxhkd;"
  54.     echo "'$(basename "$0") anything-else': This help."
  55. }
  56. akFiles(){
  57.     $mFM "$KDIR" $HOME/.config/autokey/data/My\ Phrases/
  58. }
  59. setSX(){
  60.     echo "Copy this output, and paste it inside your ~/.config/sxhkd/sxhkdrc file:"
  61.     echo "(Indentation matters.)"
  62.     echo
  63.     printf "#rofi-autokey\n"
  64.     printf "super + k\n"
  65.     printf "\trofi-autokey\n"
  66.     printf "super + shift + k\n"
  67.     printf "\trofi-autokey -\n"
  68.     echo
  69. }
  70. setKeys(){
  71.     #echo "Updating dataset..." >/dev/stderr
  72.     rm -rf "$KDIR" 2>/dev/null
  73.     mkdir "$KDIR"
  74.     cp $HOME/.config/autokey/data/My\ Phrases/*.txt "$KDIR"
  75.     #echo "Dataset updated." >/dev/stderr
  76. }
  77. main(){
  78.     aksel=`grep -e "" $KDIR/*.txt | cut -d'/' -f7- | rofi -dmenu -p "Autokeys" | cut -d':' -f1`
  79.     [[ "$aksel" = "" ]] && exit
  80.     if [[ -f $KDIR/$aksel ]]; then
  81.         cat $KDIR/$aksel | xclip -sel clip || $mFM $KDIR
  82.         notify-send -u low "$(echo $aksel|cut -d '.' -f 1) : " "in clipboard"
  83.         [ "$1" = '-' ] && xdotool type "`cat $KDIR/$aksel`"
  84.     else
  85.         notify-send -u critical "Error:" "$KDIR/$aksel"
  86.     fi
  87. }
  88. case "$1" in
  89.     '');;
  90.     '-');;
  91.     'f')
  92.         akFiles
  93.         exit
  94.         ;;
  95.     'upd')
  96.         setKeys
  97.         ;;
  98.     'sx')
  99.         setSX
  100.         exit
  101.         ;;
  102.     *)
  103.         Usage
  104.         exit
  105. esac
  106.  
  107. #Comment the line below to update 'aKeys' dataset on demand only (rofi-autokey upd)
  108. setKeys
  109.  
  110. main "$1"
Advertisement
Add Comment
Please, Sign In to add comment