From 58d007dadd07a66e2d63bf32b44ccc886535c03d Mon Sep 17 00:00:00 2001 From: D630 Date: Thu, 28 May 2015 05:11:33 +0200 Subject: [PATCH] insert section 'Toggle options' --- Examples.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/Examples.md b/Examples.md index 55585e6..c0505b7 100644 --- a/Examples.md +++ b/Examples.md @@ -136,6 +136,53 @@ builtin bind -x '"\C-x1": __fzf_history'; builtin bind '"\C-r": "\C-x1\e^\er"' ``` +### Toggle options + +```sh +# Toggle bash options (set and shopt) + +BOLD=$(tput bold || tput md) +#RESET=$(tput sgr0 || tput me) +GREEN=$(tput setaf 2 || tput AF 2) +RED=$(tput setaf 1) +#WHITE=$(tput setaf 7 || tput AF 7) + +while read -r b o n _ +do + case $b in + shopt) + if [[ $o == -u ]] + then + shopt -s "$n" + else + shopt -u "$n" + fi + ;; + set) + if [[ $o == \+o ]] + then + set -o "$n" + else + set +o "$n" + fi + ;; + esac +done < <( + < <(shopt -p ; shopt -op) sed " + / -[so] / { + s/$/ ${BOLD}${GREEN}enabled/; + b return + }; { + s/$/ ${BOLD}${RED}disabled/; + }; + : return; + " | + sort -k 3 | + column -t | + fzf --ansi --multi --with-nth=3.. --tiebreak=begin +) +``` + ### Processes ```sh