Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rofi-aliases mode script #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions mode-scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Binary file added mode-scripts/rofi-aliases.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions mode-scripts/rofi-aliases.sh
Original file line number Diff line number Diff line change
@@ -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}'