Skip to content

Commit

Permalink
feat: add --[no-]text cli arg
Browse files Browse the repository at this point in the history
useful for having icon-only power menu
see also: davatorium/rofi#1132
  • Loading branch information
cyyynthia committed May 24, 2022
1 parent 368ba43 commit ec80a15
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Available options:
--[no-]symbols Show Unicode symbols or not. Requires a font with support
for the symbols. Use, for instance, fonts from the
Nerdfonts collection. By default, they are shown
--[no-]text Show text description or not.
-h,--help Show this help text.
```

Expand Down
25 changes: 23 additions & 2 deletions rofi-power-menu
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ confirmations=(reboot shutdown logout)
# By default, no dry run
dryrun=false
showsymbols=true
showtext=true

function check_valid {
option="$1"
Expand All @@ -67,7 +68,7 @@ function check_valid {
}

# Parse command-line options
parsed=$(getopt --options=h --longoptions=help,dry-run,confirm:,choices:,choose:,symbols,no-symbols --name "$0" -- "$@")
parsed=$(getopt --options=h --longoptions=help,dry-run,confirm:,choices:,choose:,symbols,no-symbols,text,no-text --name "$0" -- "$@")
if [ $? -ne 0 ]; then
echo 'Terminating...' >&2
exit 1
Expand Down Expand Up @@ -106,6 +107,7 @@ while true; do
echo " --[no-]symbols Show Unicode symbols or not. Requires a font with support"
echo " for the symbols. Use, for instance, fonts from the"
echo " Nerdfonts collection. By default, they are shown"
echo " --[no-]text Show text description or not."
echo " -h,--help Show this help text."
exit 0
;;
Expand Down Expand Up @@ -137,6 +139,14 @@ while true; do
showsymbols=false
shift 1
;;
"--text")
showtext=true
shift 1
;;
"--no-text")
showtext=false
shift 1
;;
"--")
shift
break
Expand All @@ -148,6 +158,12 @@ while true; do
esac
done

if [ "$showsymbols" = "false" -a "$showtext" = "false" ]
then
echo "Invalid options: cannot have --no-symbols and --no-text enabled at the same time." >&2
exit 1
fi

# Define the messages after parsing the CLI options so that it is possible to
# configure them in the future.

Expand All @@ -156,7 +172,12 @@ function write_message {
text="<span font_size=\"medium\">$2</span>"
if [ "$showsymbols" = "true" ]
then
echo -n "\u200e$icon \u2068$text\u2069"
if [ "$showtext" = "true" ]
then
echo -n "\u200e$icon \u2068$text\u2069"
else
echo -n "\u200e$icon"
fi
else
echo -n "$text"
fi
Expand Down

0 comments on commit ec80a15

Please sign in to comment.