From 28012b6257b4902a1b1c1e581795474165309bdd Mon Sep 17 00:00:00 2001 From: Riyyi Date: Sat, 20 Oct 2018 22:00:56 +0200 Subject: [PATCH] Simplify help function, add help to mediacontrol.sh --- .scripts/mediacontrol.sh | 37 +++++++++++++++++++++ .scripts/vimplugin.sh | 56 ++++++++++++++++---------------- dotfiles.sh | 69 ++++++++++++++++++++-------------------- 3 files changed, 100 insertions(+), 62 deletions(-) diff --git a/.scripts/mediacontrol.sh b/.scripts/mediacontrol.sh index df255d6..e77a121 100755 --- a/.scripts/mediacontrol.sh +++ b/.scripts/mediacontrol.sh @@ -6,6 +6,42 @@ RELOAD="pkill -RTMIN+1 i3blocks" [ -z "$2" ] && NUM="2" || NUM="$2" +help() { + B=$(tput bold) + N=$(tput sgr0) + + cat << EOF +${B}NAME${N} + mediacontrol - control the volume of the system + +${B}SYNOPSIS${N} + ./mediacontrol.sh [] + +${B}DESCRIPTION${N} + Commands can be truncated, i.e. + \`${B}mediacontrol.sh t${N}\` for \`${B}mediacontrol.sh toggle${N}\` + + Arguments need to be of numeric value. + +${B}COMMANDS${N} + ${B}u*, up ${N} + + ${B}d*, down ${N} + + ${B}s*, set ${N} + + ${B}t*, toggle${N} + + ${B}m*, mute${N} + + ${B}u*, unmute${N} + + ${B}getv*, getvolume${N} + + ${B}getm*, getmute${N} +EOF +} + case "$1" in u*) pulsemixer --change-volume +"$NUM" ; $RELOAD ;; d*) pulsemixer --change-volume -"$NUM" ; $RELOAD ;; @@ -15,4 +51,5 @@ case "$1" in u*) pulsemixer --unmute ; $RELOAD ;; getv*) pulsemixer --get-volume | awk '{print $1}' ;; getm*) pulsemixer --get-mute ;; + *) help ;; esac diff --git a/.scripts/vimplugin.sh b/.scripts/vimplugin.sh index 9146062..4702edf 100755 --- a/.scripts/vimplugin.sh +++ b/.scripts/vimplugin.sh @@ -9,33 +9,33 @@ START="$DIR/start" OPT="$DIR/opt" help() { - BOLD=$(tput bold) - NORMAL=$(tput sgr0) - - echo "${BOLD}NAME${NORMAL}" - echo " vimplugin - vim plugin manager" - echo "" - echo "${BOLD}SYNOPSIS${NORMAL}" - echo " ./vimplugin.sh [ ]" - echo "" - echo "${BOLD}COMMANDS${NORMAL}" - echo " init" - echo " Creates all the required directories/files." - echo "" - echo " install [\"start\"/\"opt\"]" - echo " Install a new plugin, need to be a valid \ -GitHub URL, - start/opt to install the plugin in the start/opt directory \ -(default: start)." - echo "" - echo " list " - echo " Prints all the installed plugins, prints \ -just the plugin in that position." - echo " remove" - echo " Remove plugin, script will prompt a selection menu." - echo " update" - echo " Installs/updates all plugins from the config file." - echo "" + B=$(tput bold) + N=$(tput sgr0) + + cat << EOF +${B}NAME${N} + vimplugin - vim plugin manager + +${B}SYNOPSIS${N} + ./vimplugin.sh [ ] + +${B}COMMANDS${N} + ${B}init${N} + Creates all the required directories/files. + + ${B}install ["start"/"opt"]${N} + Install a new plugin, need to be a valid GitHub URL, + start/opt to install the plugin in the start/opt directory + (default: start). + + ${B}list ${N} + Prints all the installed plugins, + prints just the plugin in that position. + ${B}remove${N} + Remove plugin, script will prompt a selection menu. + ${B}update${N} + Installs/updates all plugins from the config file. +EOF } init() { @@ -146,6 +146,6 @@ remove() { if type "$1" 2> /dev/null | grep -q "function"; then "$@" else - echo "script: command not found: $1" + help fi diff --git a/dotfiles.sh b/dotfiles.sh index a45b2f3..c10290d 100755 --- a/dotfiles.sh +++ b/dotfiles.sh @@ -14,39 +14,40 @@ FILES=$(find . \( -path ./.git -o \ -path ./screenshot.png \) -prune -o -type f -print) if [ "$1" == "help" ] || [ "$1" == "" ]; then - BOLD=$(tput bold) - NORMAL=$(tput sgr0) - - echo "${BOLD}NAME${NORMAL}" - echo " dotfiles - file copy script for this repository" - echo "" - echo "${BOLD}SYNOPSIS${NORMAL}" - echo " ./dotfiles.sh []" - echo "" - echo "${BOLD}COMMANDS${NORMAL}" - echo " list" - echo " Prints all the dotfiles added to this directory." - echo "" - echo " get " - echo " Add file to this directory." - echo "" - echo " pull" - echo " For each file in this directory, copy that file \ -on the system to this directory." - echo "" - echo " push" - echo " For each file in this directory, copy that file \ -to its location on the system." - echo "" - echo " package [list]" - echo " List all the packages installed on the system." - echo "" - echo " package store" - echo " Store the list of all the installed packages on the \ -system." - echo "" - echo " package install" - echo " Install all the core packages of the list." + B=$(tput bold) + N=$(tput sgr0) + + cat << EOF +${B}NAME${N} + dotfiles - file copy script for the dotfiles repository + +${B}SYNOPSIS${N} + ./dotfiles.sh [] + +${B}COMMANDS${N} + ${B}list${N} + Print all files added to the dotfiles directory. + + ${B}get ${N} + Add file to the dotfiles directory. + + ${B}pull${N} + For each file in the dotfiles directory, copy that file on the system to + the dotfiles directory. + + ${B}push${N} + For each file in the dotfiles directory, copy that file to its location + on the system. + + ${B}packages [list]${N} + List all the packages installed on the system. + + ${B}packages store${N} + Store the list of all the installed packages on the system. + + ${B}packages install${N} + Install all the core packages of the list. +EOF elif [ "$1" == "list" ]; then for f in $FILES; do @@ -91,7 +92,7 @@ elif [ "$1" == "pull" ] || [ "$1" == "push" ]; then fi done -elif [ "$1" == "package" ]; then +elif [ "$1" == "packages" ]; then PACKAGE_LIST=$(comm -23 <(pacman -Qeq | sort) <(pacman -Qgq base base-devel | sort)) if [ "$2" == "list" ] || [ "$2" == "" ]; then