rofi-aliases.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env bash
  2. # A rofi mode script that allows bash aliases to be run
  3. # by Adnan Shameem. License: MIT (Expat)
  4. #
  5. # Usage:
  6. # - Download this into a dir
  7. # - Make sure it's executable: chmod +x rofi-aliases.sh
  8. # - Make sure you have $TERMINAL set or change the "TERMINAL=" line below
  9. # - Run: rofi -modi "aliases:./rofi-aliases.sh" -show aliases
  10. # or, use this to include both run and alias options: rofi -combi-modi run,"aliases:./rofi-aliases.sh" -show combi
  11. # Handle input
  12. # Important! It has to be before anything else is done in the script.
  13. # Otherwise it will keep reopening the menu indefinitely!
  14. if [ ! -z "$@" ]; then
  15. if [ -z "$TERMINAL" ]; then
  16. # Fallback if $TERMINAL is not set
  17. # Set this to anything you like
  18. TERMINAL="lxterminal"
  19. fi
  20. $TERMINAL -e "echo \"Running alias '$@'...\"; bash -i -c \"$@\"; echo \"Press Ctrl+D to exit this terminal...\"; read"
  21. exit 0
  22. fi
  23. # Change prompt
  24. echo -en "\0prompt\x1falias\n"
  25. # For alias call to work
  26. shopt -s expand_aliases
  27. test -f $HOME/.bash_aliases && source $HOME/.bash_aliases
  28. # List alias entries
  29. alias | awk -F '=' '{print $1}' | grep '^alias ' | awk '{print $2}'