From 1a111a97d685092997e11204f36a153e4a874ea8 Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Fri, 20 Sep 2019 20:08:13 -0300 Subject: [PATCH] Fix indentation (#8) The code was indented using `dot code beautify` Related: https://github.com/denisidoro/dotfiles --- src/arg.sh | 60 ++++++++++++++++++++++++------------------------ src/cheat.sh | 32 +++++++++++++------------- src/docs.sh | 20 ++++++++-------- src/main.sh | 54 +++++++++++++++++++++---------------------- src/misc.sh | 2 +- src/selection.sh | 32 +++++++++++++------------- src/str.sh | 24 +++++++++---------- src/ui.sh | 14 +++++------ test/core.sh | 6 ++--- 9 files changed, 122 insertions(+), 122 deletions(-) diff --git a/src/arg.sh b/src/arg.sh index 418919c..bcf09e5 100644 --- a/src/arg.sh +++ b/src/arg.sh @@ -1,54 +1,54 @@ #!/usr/bin/env bash arg::fn() { - awk -F'---' '{print $1}' + awk -F'---' '{print $1}' } arg::opts() { - awk -F'---' '{print $2}' + awk -F'---' '{print $2}' } arg::interpolate() { - local readonly arg="$1" - local readonly value="$2" + local readonly arg="$1" + local readonly value="$2" - sed "s|<${arg}>|\"${value}\"|g" + sed "s|<${arg}>|\"${value}\"|g" } arg::next() { - grep -Eo '<[0-9a-zA-Z\-_]+>' \ + grep -Eo '<[0-9a-zA-Z\-_]+>' \ | head -n1 \ | tr -d '<' \ | tr -d '>' } arg::pick() { - local readonly arg="$1" - local readonly cheat="$2" + local readonly arg="$1" + local readonly cheat="$2" - local readonly prefix="$ ${arg}:" - local readonly length="$(echo "$prefix" | str::length)" - local readonly arg_description="$(grep "$prefix" "$cheat" | str::sub $((length + 1)))" + local readonly prefix="$ ${arg}:" + local readonly length="$(echo "$prefix" | str::length)" + local readonly arg_description="$(grep "$prefix" "$cheat" | str::sub $((length + 1)))" - local readonly fn="$(echo "$arg_description" | arg::fn)" - local readonly args_str="$(echo "$arg_description" | arg::opts | tr ' ' '\n' || echo "")" - local arg_name="" + local readonly fn="$(echo "$arg_description" | arg::fn)" + local readonly args_str="$(echo "$arg_description" | arg::opts | tr ' ' '\n' || echo "")" + local arg_name="" - for arg_str in $args_str; do - if [ -z $arg_name ]; then - arg_name="$(echo "$arg_str" | str::sub 2)" - else - eval "local $arg_name"='$arg_str' - arg_name="" - fi - done + for arg_str in $args_str; do + if [ -z $arg_name ]; then + arg_name="$(echo "$arg_str" | str::sub 2)" + else + eval "local $arg_name"='$arg_str' + arg_name="" + fi + done - if [ -n "$fn" ]; then - eval "$fn" | ui::pick --prompt "$arg: " --header-lines "${headers:-0}" | str::column "${column:-}" - else - printf "\033[0;36m${arg}:\033[0;0m " > /dev/tty - read value - ui::clear_previous_line > /dev/tty - printf "$value" - fi + if [ -n "$fn" ]; then + eval "$fn" | ui::pick --prompt "$arg: " --header-lines "${headers:-0}" | str::column "${column:-}" + else + printf "\033[0;36m${arg}:\033[0;0m " > /dev/tty + read value + ui::clear_previous_line > /dev/tty + printf "$value" + fi } diff --git a/src/cheat.sh b/src/cheat.sh index 5ce0208..c62185d 100755 --- a/src/cheat.sh +++ b/src/cheat.sh @@ -1,33 +1,33 @@ #!/usr/bin/env bash cheat::find() { - find "${NAVI_DIR:-"${SCRIPT_DIR}/cheats"}" -iname '*.cheat' + find "${NAVI_DIR:-"${SCRIPT_DIR}/cheats"}" -iname '*.cheat' } cheat::read_many() { - for cheat in $(cat); do - awk ' + for cheat in $(cat); do + awk ' function color(c,s) { printf("\033[%dm%s\033[0m",30+c,s) } - + /^%/ { tags=" ["substr($0, 3)"]"; next } /^#/ { print color(4, $0) color(60, tags); next } /^\$/ { next } - NF { print color(7, $0) color(60, tags); next }' "$cheat" - done + NF { print color(7, $0) color(60, tags); next }' "$cheat" + done } cheat::from_selection() { - local readonly cheats="$1" - local readonly selection="$2" - - local readonly tags="$(echo "$selection" | selection::tags)" + local readonly cheats="$1" + local readonly selection="$2" - for cheat in $cheats; do - if grep -q "% $tags" "$cheat"; then - echo "$cheat" - break - fi - done + local readonly tags="$(echo "$selection" | selection::tags)" + + for cheat in $cheats; do + if grep -q "% $tags" "$cheat"; then + echo "$cheat" + break + fi + done } diff --git a/src/docs.sh b/src/docs.sh index ad03944..a72117e 100644 --- a/src/docs.sh +++ b/src/docs.sh @@ -13,16 +13,16 @@ docs::eval() { interpolation=true for arg in $@; do - case $wait_for in - dir) NAVI_DIR="$arg"; wait_for="";; - esac + case $wait_for in + dir) NAVI_DIR="$arg"; wait_for="" ;; + esac - case $arg in - --print) print=true;; - --no-interpolation) interpolation=false;; - --version) echo "${VERSION:-unknown}" && exit 0;; - --help) docs::extract_help "$0" && exit 0;; - -d|--dir) wait_for="dir";; - esac + case $arg in + --print) print=true ;; + --no-interpolation) interpolation=false ;; + --version) echo "${VERSION:-unknown}" && exit 0 ;; + --help) docs::extract_help "$0" && exit 0 ;; + -d|--dir) wait_for="dir" ;; + esac done } diff --git a/src/main.sh b/src/main.sh index b94f791..a778e58 100644 --- a/src/main.sh +++ b/src/main.sh @@ -2,36 +2,36 @@ set -euo pipefail main() { - local readonly cheats="$(cheat::find)" - local readonly selection="$(ui::select "$cheats")" - local readonly cheat="$(cheat::from_selection "$cheats" "$selection")" - local cmd="$(selection::command "$selection" "$cheat")" - local arg value + local readonly cheats="$(cheat::find)" + local readonly selection="$(ui::select "$cheats")" + local readonly cheat="$(cheat::from_selection "$cheats" "$selection")" + local cmd="$(selection::command "$selection" "$cheat")" + local arg value - if ! $interpolation; then - echo "$cmd" - exit 0 - fi + if ! $interpolation; then + echo "$cmd" + exit 0 + fi - while true; do - arg="$(echo "$cmd" | arg::next || echo "")" - if [ -z "$arg" ]; then - break - fi + while true; do + arg="$(echo "$cmd" | arg::next || echo "")" + if [ -z "$arg" ]; then + break + fi - value="$(arg::pick "$arg" "$cheat" || echo "")" - if [ -z "$value" ]; then - echo "$cmd" - exit 0 - fi + value="$(arg::pick "$arg" "$cheat" || echo "")" + if [ -z "$value" ]; then + echo "$cmd" + exit 0 + fi - eval "local $arg"='$value' - cmd="$(echo "$cmd" | arg::interpolate "$arg" "$value")" - done + eval "local $arg"='$value' + cmd="$(echo "$cmd" | arg::interpolate "$arg" "$value")" + done - if $print; then - echo "$cmd" - else - eval "$cmd" - fi + if $print; then + echo "$cmd" + else + eval "$cmd" + fi } diff --git a/src/misc.sh b/src/misc.sh index 3efd1bd..29e1f7e 100644 --- a/src/misc.sh +++ b/src/misc.sh @@ -2,5 +2,5 @@ # no-op hack to set dependency order resolution dep() { - : + : } diff --git a/src/selection.sh b/src/selection.sh index a0a2d3d..481df15 100644 --- a/src/selection.sh +++ b/src/selection.sh @@ -1,36 +1,36 @@ #!/usr/bin/env bash selection::standardize() { - local readonly str="$(cat)" + local readonly str="$(cat)" - local readonly tags="$(echo "$str" | awk -F'[' '{print $NF}' | tr -d ']')" - local readonly core="$(echo "$str" | sed -e "s/ \[${tags}\]$//")" + local readonly tags="$(echo "$str" | awk -F'[' '{print $NF}' | tr -d ']')" + local readonly core="$(echo "$str" | sed -e "s/ \[${tags}\]$//")" - echo "${core}^${tags}" + echo "${core}^${tags}" } selection::core() { - cut -d'^' -f1 + cut -d'^' -f1 } selection::tags() { - cut -d'^' -f2 + cut -d'^' -f2 } selection::core_is_comment() { - grep -qE '^#' + grep -qE '^#' } selection::command() { - local readonly selection="$1" - local readonly cheat="$2" + local readonly selection="$1" + local readonly cheat="$2" - local readonly core="$(echo $selection | selection::core)" + local readonly core="$(echo $selection | selection::core)" - if echo "$core" | selection::core_is_comment; then - grep "$core" "$cheat" -A999 \ - | str::last_paragraph_line - else - echo "$core" - fi + if echo "$core" | selection::core_is_comment; then + grep "$core" "$cheat" -A999 \ + | str::last_paragraph_line + else + echo "$core" + fi } diff --git a/src/str.sh b/src/str.sh index b2a66b8..7c72826 100644 --- a/src/str.sh +++ b/src/str.sh @@ -1,27 +1,27 @@ #!/usr/bin/env bash str::length() { - awk '{print length}' + awk '{print length}' } str::sub() { - local readonly start="${1:-0}" - local readonly finish="${2:-99999}" + local readonly start="${1:-0}" + local readonly finish="${2:-99999}" - cut -c "$((start + 1))-$((finish - 1))" + cut -c "$((start + 1))-$((finish - 1))" } str::column() { - local readonly n="${1:-}" + local readonly n="${1:-}" - if [ -n "$n" ]; then - awk "{print \$$n}" - else - cat - fi + if [ -n "$n" ]; then + awk "{print \$$n}" + else + cat + fi } str::last_paragraph_line() { - awk '(!NF) { exit } { print $0 }' \ - | tail -n1 + awk '(!NF) { exit } { print $0 }' \ + | tail -n1 } diff --git a/src/ui.sh b/src/ui.sh index 1d39c40..7d0091d 100644 --- a/src/ui.sh +++ b/src/ui.sh @@ -1,18 +1,18 @@ #!/usr/bin/env bash ui::pick() { - fzf --height '100%' --inline-info "$@" + fzf --height '100%' --inline-info "$@" } ui::select() { - local readonly cheats="$1" + local readonly cheats="$1" - echo "$cheats" \ - | cheat::read_many \ - | ui::pick -i --ansi \ - | selection::standardize + echo "$cheats" \ + | cheat::read_many \ + | ui::pick -i --ansi \ + | selection::standardize } ui::clear_previous_line() { - tput cuu1 && tput el || true + tput cuu1 && tput el || true } diff --git a/test/core.sh b/test/core.sh index 78d578e..726cdbf 100644 --- a/test/core.sh +++ b/test/core.sh @@ -4,10 +4,10 @@ source <( grep -v 'main ' "${SCRIPT_DIR}/navi" | sed -E "s|export.*|export SCRIPT_DIR=\"${SCRIPT_DIR}\"|") test::success() { - echo "Test passed!" + echo "Test passed!" } test::fail() { - echo "Test failed..." - exit 42 + echo "Test failed..." + exit 42 } \ No newline at end of file