-
Notifications
You must be signed in to change notification settings - Fork 0
Home
This repository contains various shell scripts, each designed for specific tasks. Below you'll find explanations and usage instructions for some of included scripts.
- utils
- timer
- maimpick
- record
- vpn-connect
- wifi-connect
- wifi-hotspot
- myip
- nmtui-connect
- pinentry-dmenu
- totp
- encrypt-file
- media-control
- autostart
- clear-cache
- display-select
- display-toggle
This utility script provides common functions that can be sourced into other scripts to enhance maintainability and reduce redundancy. Below is an explanation of the purpose and usage of each function included in this script.
The prompt function provides a way to prompt the user for input using either fzf in a terminal or dmenu in a graphical environment. It ensures that the script can ask for user input in different environments (headless or with a graphical display).
prompt [title] [optional list]
-
$1
: The prompt message to display. -
$2
: Optional. The list of entries to be shown for the picking.
If the script is running in a terminal-only environment (no graphical display), it uses fzf
.
If a graphical environment is detected, it uses dmenu
for the prompt.
The function handles the special case where a terminal prompt is requested even in a graphical environment via the USE_TERM variable.
-
enter
: Submit text in case when list is not provided and prompt is used to pick up text instead list selection -
ctrl + j
: This shortcut will submit the entered text even if the list is set.ctrl + j
is used because my terminal outputs that when pressingshift + enter
which is impossible shortcut for some terminal apps
prompt 'Destination:' $'Clipboard\nFile\nBoth'
The notify function sends notifications to the user. It uses notify-send in a graphical environment and falls back to a simple printf in a terminal-only environment.
notify [title] [message]
The getpass
securely prompts the user for a password or other sensitive input, hiding the input as it is typed.
Usage
getpass [message]
-
$1
: The prompt message to display.
In a terminal-only environment, it uses read -s to hide the input while typing.
In a graphical environment, it uses dmenu with password mode patched in.
password=$(getpass "Enter your password: ")
The getfilename
generates a unique filename in a specified directory, avoiding name collisions by appending a number if the filename already exists.
getfilename [desired file name] [path for the file]
-
$1
: The desired filename. -
$2
: The directory in which to check for existing filenames.
If a file with the same name already exists, it increments a number at the end of the filename until a unique name is found.
If the filename begins with a dot (hidden file), the function preserves this.
unique_filename=$(getfilename "example.txt" "/path/to/dir/")
The wait
repeatedly attempts to execute a command until it succeeds or a maximum number of attempts is reached. It is useful for waiting for certain conditions to be met, such as when a network connection is established after manipulating it.
wait [command]
-
$1
: The command to execute
The function tries to execute the command up to 20 times, with a 0.5-second delay between attempts.
If the command succeeds, the function exits the loop early.
wait "ping -c 1 8.8.8.8 -W 1 > /dev/null"
The Timer Script allows users to set a countdown timer or specify an absolute end time. Upon completion, the script will print a message and send a system notification with "critical" urgency.
timer [time]
The script accepts the following input formats:
-
HH:MM:SS format
Example:
01:30:00
Sets a countdown timer for 1 hour, 30 minutes, and 0 seconds.
-
Seconds (Numeric Value)
Example:
3600
Sets a countdown timer for the specified number of seconds (e.g., 3600 seconds equals 1 hour).
Handles up to 86400 seconds (24 hours).
-
Absolute Timestamp (Unix Epoch Time)
Example:
1700000000
Sets the timer to end at a specific Unix timestamp. If the timestamp is in the past, the timer will immediately finish.
This script simplifies the process of taking screenshots by providing an interactive interface for selecting the capture type and destination. It supports multiple monitors, window selection, and delayed captures with a timer. The screenshots can be saved to a default directory, copied to the clipboard, or both. The script uses import
command from ImageMagick for capturing the screenshot and selx command for selecting a screen region
maimpick [arguments]
-
-a
: Automatically capture the active window and save the screenshot to a file
This script provides an interface for recording screen content. It allows user to select between recording a specific region, an entire window, or any active monitor connected to the system. The script leverages ffmpeg
for capturing and encoding the video and selx command for selecting a screen region
This script simplifies the process of connecting to a VPN using OpenVPN configuration files stored in a specific directory (~/.local/share/ovpn). It uses user credentials stored with secret-tool and handles the VPN connection securely by managing temporary files and cleaning up after use.
vpn-connect [-q]
-
$1
: If anything is provided as an argument, the script will terminate the active VPN connection
It is required to have credentials stored like:
secret-tool store --label "VPN <VPN config name>" user "<OpenVPN config file name without extension>"
secret-tool store --label "VPN <VPN config name>" pass "<OpenVPN config file name without extension>"
This script provides a simple interface for scanning available Wi-Fi networks and connecting to them using the iwctl
command-line tool. It offers an interactive prompt to select a network, enter a password if required, and establish a connection. It also supports disconnecting from the current Wi-Fi network.
wifi-connect [-q]
-
-q
: If the -q argument is provided, the script will disconnect the current Wi-Fi connection
This script is used to manage a Wi-Fi hotspot using the hostapd
service.
wifi-hotspot [-q]
-
-q
: Stops the Wi-Fi hotspot by terminating the hostapd process.
This script will fetch and display IP-based location information (country, city, IP address). If provided with additional input arguments it will also show the active VPN name and Wi-Fi SSID. The script does not have a mode to show all active networks but instead relies on nmtui-connect to provide it appropriate args
myip [options]
-
-c
: Enables colored output for terminal mode. -
-h
: Displays hardcoded information about an active hotspot. -
-v
: Displays information about active VPN connections. -
-w
: Displays information about the currently connected Wi-Fi network.
This script provides an interactive menu for managing various network interfaces such as VPN, Wi-Fi, and Wi-Fi hotspots with help of vpn-connect, wifi-connect and wifi-hotspot scripts for the functional part and myip for the preview shown in fzf
. Is is created as an alternative for the tool of the same name from the NetworkManager suite (so rename if you have nm)
This script acts as a custom Polkit agent that handles password prompts by requesting user input via dmenu. It is used as an alternative to polkit-gnome
or similar agents used to elevate privileges. It depends on cmd-polkit
.
This script is designed work as a GPG program that will interact with a protocol that requests a passphrase, handles command-based communication, and sets custom prompts. It operates in a loop, responding to specific commands for a predetermined number of iterations. Created to make a consistent interface with my other scripts and because of that it uses dmenu
with password
patch applied to hide keyboard input.
It is required to have pinentry-program
set in the ~/.local/share/gnupg/gpg-agent.conf
like:
pinentry-program /home/dusan/.local/bin/pinentry-dmenu
Being a alternative to mobile apps like Google Authenticator or Aegis, this script interacts with encrypted TOTP keys stored in a specific directory, decrypts a selected key using GPG, generates a TOTP based on that key, and copies the TOTP to the clipboard. The TOTP is also echoed to the terminal.
$XDG_DATA_HOME/secrets/priv: This file should contain the necessary GPG settings, such as gpgKey and email, used for decryption.
gpgKey="123abc"
email="[email protected]"
$XDG_DATA_HOME/totp/: This directory stores the GPG-encrypted TOTP keys. Aegis stores this key as a "secret". The encrypt-file script can be used to encrypt the key
This script encrypts a specified file using GPG and deletes the original plaintext file if the encryption is successful.
encrypt-file [file path]
This script sends media control commands (e.g., Play, Pause, Next, Previous) to running MPRIS-compatible media players via D-Bus. If no media player is available or the command is not supported, it falls back to controlling MPD (Music Player Daemon). Useful if you want to control a YouTube via keyboard or Bluetooth headphones.
media-control [command]
-
$1
: Command to be passed on to the media player e.g. Play, Pause, Next, Previous
The script runs on startup, but during work hours, it opens several apps and browser tabs, activates a hotspot, and configures three monitors instead of the default two.
This script prunes VSCode workspaces, clears cache directories, deduplicates history files, and cleans up journal logs and package cache.
This script manages multiple monitors using xrandr, allowing you to arrange displays interactively based on your selection.
This script toggles the state of connected displays (on/off) based on the input argument. I am using if from dwm
to toggle monitors using keyboard shortcuts
display-toggle [display index]
display-toggle 0
-
$1
: The index of the display to toggle, starting from 0.