diff options
author | venomade <venomade@venomade.com> | 2025-02-27 17:06:42 +0000 |
---|---|---|
committer | venomade <venomade@venomade.com> | 2025-02-27 17:06:42 +0000 |
commit | 1cace80e4832a5d250ef4b7ccd687996563fb01b (patch) | |
tree | db1ced91d1382ca3cabe37dbae00da51231d6a99 /nixos/scripts/dm-man |
Add old dotfiles
Diffstat (limited to 'nixos/scripts/dm-man')
-rwxr-xr-x | nixos/scripts/dm-man | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/nixos/scripts/dm-man b/nixos/scripts/dm-man new file mode 100755 index 0000000..2b4688b --- /dev/null +++ b/nixos/scripts/dm-man @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +# +# Script name: dm-man +# Description: Search for a manpage or get a random one. +# Dependencies: dmenu, fzf, rofi, alacritty (edit DMTERM in dmscripts config if using another terminal) +# GitLab: https://www.gitlab.com/dwt1/dmscripts +# License: https://www.gitlab.com/dwt1/dmscripts/LICENSE +# Contributors: Derek Taylor +# Simon Ingelsson + +# Set with the flags "-e", "-u","-o pipefail" cause the script to fail +# if certain things happen, which is a good thing. Otherwise, we can +# get hidden bugs that are hard to discover. +set -euo pipefail + +# shellcheck disable=SC1091 +source ./_dm-helper.sh 2>/dev/null || source _dm-helper.sh 2>/dev/null + +source_dmscripts_configs + +if configs_are_different; then + echo "$(date): configs are different" >>"$DM_CONFIG_DIFF_LOGFILE" + sleep 1 +fi + +main() { + # An array of options to choose. + local _options=("Search manpages" "Random manpage" "Quit") + # Piping the above array into dmenu. + # We use "printf '%s\n'" to format the array one item to a line. + choice=$(printf '%s\n' "${_options[@]}" | ${MENU} 'Manpages:') + + # What to do when/if we choose one of the options. + case "$choice" in + 'Search manpages') + # shellcheck disable=SC2086 + man -k . | awk '{$3="-"; print $0}' \ + | ${MENU} 'Search for:' \ + | awk '{print $2, $1}' | tr -d '()' | xargs $DMTERM man + ;; + 'Random manpage') + # shellcheck disable=SC2086 + man -k . | cut -d' ' -f1 | shuf -n 1 \ + | ${MENU} 'Random manpage:' | xargs $DMTERM man + ;; + 'Quit') + echo "Program terminated." && exit 0 + ;; + *) + exit 0 + ;; + esac + +} + +MENU="$(get_menu_program "$@")" +[[ "${BASH_SOURCE[0]}" == "${0}" ]] && main |