diff --git a/mode-scripts/README.md b/mode-scripts/README.md index 240b799..9a20286 100644 --- a/mode-scripts/README.md +++ b/mode-scripts/README.md @@ -15,3 +15,25 @@ rofi -modi "fb:./rofi-file-browser.sh" -show fb ### Screenshot ![Rofi File Browser](rofi-file-browser.png) + +## Aliases + +### Usage + +Remember to have a valid `$TERMINAL` set on system or change the `TERMINAL=` line on `rofi-aliases.sh`. + +To get a list of aliases: + +```bash +rofi -modi "aliases:./rofi-aliases.sh" -show aliases +``` + +or, to use in combination with run: + +```bash +rofi -combi-modi run,"aliases:./rofi-aliases.sh" -show combi +``` + +### Screenshot + +![Rofi Aliases](rofi-aliases.png) diff --git a/mode-scripts/rofi-aliases.png b/mode-scripts/rofi-aliases.png new file mode 100644 index 0000000..2f90bd0 Binary files /dev/null and b/mode-scripts/rofi-aliases.png differ diff --git a/mode-scripts/rofi-aliases.sh b/mode-scripts/rofi-aliases.sh new file mode 100755 index 0000000..e873f2c --- /dev/null +++ b/mode-scripts/rofi-aliases.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +# A rofi mode script that allows bash aliases to be run +# by Adnan Shameem. License: MIT (Expat) +# +# Usage: +# - Download this into a dir +# - Make sure it's executable: chmod +x rofi-aliases.sh +# - Make sure you have $TERMINAL set or change the "TERMINAL=" line below +# - Run: rofi -modi "aliases:./rofi-aliases.sh" -show aliases +# or, use this to include both run and alias options: rofi -combi-modi run,"aliases:./rofi-aliases.sh" -show combi + +# Handle input +# Important! It has to be before anything else is done in the script. +# Otherwise it will keep reopening the menu indefinitely! +if [ ! -z "$@" ]; then + if [ -z "$TERMINAL" ]; then + # Fallback if $TERMINAL is not set + # Set this to anything you like + TERMINAL="lxterminal" + fi + $TERMINAL -e "echo \"Running alias '$@'...\"; bash -i -c \"$@\"; echo \"Press Ctrl+D to exit this terminal...\"; read" + exit 0 +fi + +# Change prompt +echo -en "\0prompt\x1falias\n" + +# For alias call to work +shopt -s expand_aliases +test -f $HOME/.bash_aliases && source $HOME/.bash_aliases + +# List alias entries +alias | awk -F '=' '{print $1}' | grep '^alias ' | awk '{print $2}'