Assorted shell and Python scripts
1#!/usr/bin/env sh 2# 3# Rofi powered menu to prompt a message and get a yes/no answer. 4# Uses: rofi 5# 6# This script is a modified version of 7# https://gitlab.com/vahnrr/rofi-menus/-/blob/master/scripts/rofi-prompt 8# 9# MIT License 10# 11# Copyright (c) 2023 Jeffrey Serio <hyperreal@fedoraproject.org> 12# Copyright (c) 2020 vahnrr 13# 14# Permission is hereby granted, free of charge, to any person obtaining a copy 15# of this software and associated documentation files (the "Software"), to deal 16# in the Software without restriction, including without limitation the rights 17# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18# copies of the Software, and to permit persons to whom the Software is 19# furnished to do so, subject to the following conditions: 20# 21# The above copyright notice and this permission notice shall be included in all 22# copies or substantial portions of the Software. 23# 24# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30# SOFTWARE. 31################################################################################ 32 33yes='Confirm' 34no='Cancel' 35query='Are you sure?' 36 37while [ $# -ne 0 ]; do 38 case "$1" in 39 -y | --yes) 40 [ -n "$2" ] && yes="$2" || yes='' 41 shift 42 ;; 43 44 -n | --no) 45 [ -n "$2" ] && no="$2" || no='' 46 shift 47 ;; 48 49 -q | --query) 50 [ -n "$2" ] && query="$2" 51 shift 52 ;; 53 esac 54 shift 55done 56 57chosen=$(printf '%s;%s' "$yes" "$no" \ 58 | rofi -theme-str 'window { width: 10em; height: 11em; }' \ 59 -p "$query" \ 60 -dmenu \ 61 -sep ';' \ 62 -a 0 \ 63 -u 1 \ 64 -selected-row 1) 65 66case "$chosen" in 67 "$yes") exit 0 ;; 68 *) exit 1 ;; 69esac