Advertisement
skidd0

Untitled

Jun 23rd, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. #!/bin/bash
  2. # Creates a menu of special characters via dmenu or rofi. Once a character is
  3. # selected, it is pasted to the cursor via xdotool. Symbols can be added to the
  4. # menu on the character_list with any keyword, but make sure to keep the syntax
  5. #
  6. # syntax:
  7. # keyword :$symbol
  8. #
  9. # $symbol will be the character printed via xdotool. Anything between the
  10. # colon and the \n (linebreak) will be pasted, excluding trailing whitespace.
  11. #
  12. # note1: By modifying 'sep', a different character rather than colon could be
  13. # used, in case some of the symbols used have colons in them. For my
  14. # purpose, this has never been the case.
  15. #
  16. # note2: The xdotool is given a delay because of issues I've had with printing
  17. # long smileys, this could be removed if only single-character symbols are
  18. # desired, and it may improve the experience.
  19. #
  20. # Script Created By: https://github.com/mbfraga Feel free to do anything you
  21. # want with this script.
  22.  
  23. launcher="dmenu" # dmenu/rofi
  24. character_list="./special_character_list"
  25. sep=":"
  26.  
  27. cd $(dirname $0)
  28.  
  29. if [ $# -gt 0 ]; then
  30. if [ "$1" == "-d" ]; then
  31. launcher="dmenu"
  32. elif [ "$1" == "-r" ]; then
  33. launcher="rofi"
  34. fi
  35. fi
  36.  
  37.  
  38. if [ "$launcher" == "dmenu" ]; then
  39. if !(command -v dmenu 2>/dev/null); then
  40. echo "dmenu not installed, trying rofi..."
  41. if command -v rofi 2>/dev/null; then
  42. launcher=rofi
  43. else
  44. echo "rofi not installed either, aborting..."
  45. exit 1
  46. fi
  47. fi
  48. fi
  49.  
  50. if [ "$launcher" == "rofi" ]; then
  51. if !(command -v rofi 2>/dev/null); then
  52. echo "dmenu not installed, trying dmenu..."
  53. if command -v dmenu 2>/dev/null; then
  54. launcher=dmenu
  55. else
  56. echo "dmenu not installed either, aborting..."
  57. exit 1
  58. fi
  59. fi
  60. fi
  61.  
  62.  
  63. _rofi () {
  64. rofi -dmenu -sync -p "(symbols): " $@
  65. }
  66.  
  67. _dmenu () {
  68. dmenu -l 10 $@
  69. }
  70.  
  71.  
  72. if [ "$launcher" == "dmenu" ]; then
  73. selected_string=$(cat $character_list | _dmenu)
  74. elif [ "$launcher" == "rofi" ]; then
  75. selected_string=$(cat $character_list | _rofi)
  76. fi
  77.  
  78. selected_symbol=$(echo $selected_string | cut -d $sep -f 2-10 )
  79. #trim whitespace
  80. #selected_symbol=${selected_symbol// }
  81. selected_symbol=${selected_symbol}
  82.  
  83. xdotool type --delay 80 "$selected_symbol"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement