From aa59a3830a18ace7dd2fbf469f5b547fdbea1722 Mon Sep 17 00:00:00 2001 From: ksyasuda Date: Tue, 15 Mar 2022 10:35:39 -0700 Subject: [PATCH] add rofi-run script --- rofi/scripts/rofi-run.sh | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 rofi/scripts/rofi-run.sh diff --git a/rofi/scripts/rofi-run.sh b/rofi/scripts/rofi-run.sh new file mode 100755 index 0000000..a33ecef --- /dev/null +++ b/rofi/scripts/rofi-run.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail + +# Script to run a bash command from a rofi prompt + +THEME_STR=" +window { + width: 35%; + height: 10%; + anchor: north; + location: north; +}" + +# generates a span mesg for rofi given +# input: message: str +generate_span() { + msg1="$1" + msg2="$2" + span="$msg1" + span2="$msg2" + printf "%s: %s\n" "$span" "$span2" +} + +# Get the command to run +cmd="$(rofi -dmenu -l 0 -p 'Run:' -theme-str "$THEME_STR")" + +# Check if command is sudo +if [[ "$cmd" == "sudo"* ]]; then + # Prompt for confirmation + confirm="$(rofi -dmenu -l 0 -p 'Confirm (Y/N)' \ + -theme-str "$THEME_STR" -mesg "$(generate_span "CMD" "$cmd")" || true)" + # If not confirmed, exit + if ! [[ "$confirm" == "Y" || "$confirm" == "y" ]]; then + exit 0 + fi +fi + +if [[ "$1" == "-v" || "$1" == "--verbose" ]]; then + # Send command to dunstify + dunstify "Running command: $cmd" +fi + +# Run the command +eval "$cmd"