Skip to content

Instantly share code, notes, and snippets.

@sebastiancarlos
Last active August 23, 2023 12:05
Show Gist options
  • Save sebastiancarlos/e3b1d1264c93cc69f818851bc8d82875 to your computer and use it in GitHub Desktop.
Save sebastiancarlos/e3b1d1264c93cc69f818851bc8d82875 to your computer and use it in GitHub Desktop.
Fix column output on bash's shopt, and add color
# All my gist code is licensed under the terms of the MIT license.
# Video demo: https://www.youtube.com/watch?v=bNITSDWht6w
# add to your .bashrc or something like that
# custom shopt
# It pipes into column -t if there are no arguments,
# because the default with broken lines is not very readable.
# And while I'm at it, make 'on' green and 'off' red.
function shopt () {
if [ $# -eq 0 ]; then
local output=$(command shopt | column -t;)
output=$(echo "$output" | sed -E "s/(on$)/$(tput setaf 2)\1$(tput sgr0)/g");
output=$(echo "$output" | sed -E "s/(off$)/$(tput setaf 1)\1$(tput sgr0)/g");
echo "$output";
else
command shopt "$@";
fi;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment