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
| # 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
| # 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
| # 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
| # Password strength check function. Can be fed a password most ways. | |
| # TO-DO: add a verbose output switch | |
| pwcheck () { | |
| # Read password in, if it's blank, prompt the user | |
| if [[ "${*}" = "" ]]; then | |
| read -resp $'Please enter the password/phrase you would like checked:\n' PwdIn | |
| else | |
| # Otherwise, whatever is fed in is the password to check | |
| PwdIn="${*}" | |
| 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
| # Detect if our version of 'tput' is so old that it uses termcap syntax | |
| # If this is the case, overlay it so that newer terminfo style syntax works | |
| # Inspired by 'bashlib' and 'liquidprompt' | |
| # For performance we only implement if 'tput ce' (a harmless test) works | |
| if tput ce 2>/dev/null; then | |
| tput() { | |
| ctput-null() { command tput "${@}" 2>/dev/null; } | |
| ctput() { command tput "${@}"; } | |
| case "${1}" in | |
| (blink) ctput-null blink || ctput mb;; |
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
| # shellcheck shell=bash | |
| ################################################################################ | |
| # setprompt and related/required functions | |
| ################################################################################ | |
| # Wrap 'cd' to automatically update GIT_BRANCH when necessary | |
| cd() { | |
| command cd "${@}" || return 1 | |
| if is_gitdir; then | |
| PS1_GIT_MODE=True |
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 (( BASH_VERSINFO >= 4 )); then | |
| tolower() { | |
| # If parameter is a file, or stdin is used, action that first | |
| if [[ -r "${1}" ]]||[[ ! -t 0 ]]; then | |
| # We structure our while read loop to handle no newline at EOF | |
| eof= | |
| while [[ -z "${eof}" ]]; do | |
| read -r || eof=true | |
| printf -- '%s\n' "${REPLY,,}" | |
| done < "${1:-/dev/stdin}" |
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
| logname() { | |
| case "${1}" in | |
| (--home) | |
| getent passwd "$(command logname)" | awk -F ':' '{print $6}' | |
| ;; | |
| (*) | |
| command logname "${@}" | |
| ;; | |
| esac | |
| } |