This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Check if 'watch' is available, if not, enable a stop-gap function | |
| if ! command -v watch &>/dev/null; then | |
| watch() { | |
| local OPTIND colWidth titleHead sleepTime dateNow | |
| while getopts ":hn:vt" optFlags; do | |
| case "${optFlags}" in | |
| (h) printf '%s\n' "Usage:" " watch [-hntv] <command>" "" \ | |
| "Options:" \ | |
| " -h, help. Print a summary of the options" \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Add -p option to 'touch' to combine 'mkdir -p' and 'touch' | |
| # The trick here is that we use 'command' to launch 'touch', | |
| # as it overrides the shell's lookup order.. essentially speaking. | |
| touch() { | |
| # Check if '-p' is present. | |
| # For bash3+ you could use 'if [[ "$@" =~ -p ]];' | |
| if echo "$@" | grep "\\-p" >/dev/null 2>&1; then | |
| # Transfer everything to a local array | |
| local argArray=( "$@" ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # flocate function. This gives a search function that blends find and locate | |
| # Will obviously only work where locate lives, so Solaris will mostly be out of luck | |
| # Usage: flocate searchterm1 searchterm2 searchterm[n] | |
| # Source: http://solarum.com/v.php?l=1149LV99 | |
| flocate() { | |
| if ! command -v locate &>/dev/null; then | |
| printf '%s\n' "[ERROR]: 'flocate' depends on 'locate', which wasn't found." | |
| return 1 | |
| fi | |
| if (( $# > 1 )); then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| progWidth="${1:-3}" | |
| sleepTime="0.2" | |
| resetTerm() { | |
| tput sgr0 # Unset as many things that we've set as possible | |
| tput cnorm # Display the cursor again | |
| printf '%s\n' "" | |
| exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| progWidth="${1:-3}" | |
| sleepTime="0.2" | |
| resetTerm() { | |
| tput sgr0 # Unset as many things that we've set as possible | |
| tput cnorm # Display the cursor again | |
| printf '%s\n' "" | |
| exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Because you never know what crazy systems are out there | |
| if ! command -v apropos >/dev/null 2>&1; then | |
| apropos() { man -k "$*"; } | |
| fi | |
| # A small function to trim whitespace either side of a (sub)string | |
| # shellcheck disable=SC2120 | |
| trim() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| getAD-User-Info() { | |
| local userName adUserName | |
| userName="${1:?Username not supplied}" | |
| # Poll 'id' to either ensure the info is cached | |
| # or to error out if the user doesn't exist | |
| if ! id "${userName}" &>/dev/null; then | |
| printf -- '%s\n' "User '${userName}' could not be found" | |
| return 1 | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| date() { | |
| case "$@" in | |
| (*"%o"*) | |
| declare -a args1 | |
| declare -a args2 | |
| while [[ -n "$1" ]]; do | |
| args2+=("$1") | |
| if [[ "${1:0:1}" != + ]]; then | |
| args1+=("$1") | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pretty () { | |
| while read -r; do | |
| printf "\033[38;5;%dm%s\033[0m\n" $(($RANDOM%255)) "${REPLY}"; | |
| done | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if ! command -v cowsay &>/dev/null; then | |
| cowsay() { | |
| local msg | |
| if [[ -t 0 ]] && [[ -z $1 ]]; then | |
| msg="Moo! What should I say?" | |
| elif [[ -n $1 ]]; then | |
| msg="$*" | |
| else | |
| msg=$(paste -sd ' ' - | sed -e "s/[[:space:]]\\+/ /g") | |
| fi |