diff --git a/src/arg.sh b/src/arg.sh index b93d691..c3c2165 100644 --- a/src/arg.sh +++ b/src/arg.sh @@ -11,8 +11,8 @@ arg::opts() { } arg::interpolate() { - local readonly arg="$1" - local readonly value="$2" + local -r arg="$1" + local -r value="$2" sed "s|<${arg}>|\"${value}\"|g" } @@ -25,15 +25,15 @@ arg::next() { } arg::pick() { - local readonly arg="$1" - local readonly cheat="$2" + local -r arg="$1" + local -r 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 -r prefix="$ ${arg}:" + local -r length="$(echo "$prefix" | str::length)" + local -r 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 -r fn="$(echo "$arg_description" | arg::fn)" + local -r args_str="$(echo "$arg_description" | arg::opts | tr ' ' '\n' || echo "")" local arg_name="" for arg_str in $args_str; do diff --git a/src/cheat.sh b/src/cheat.sh index 4ff6967..1817147 100755 --- a/src/cheat.sh +++ b/src/cheat.sh @@ -21,10 +21,10 @@ cheat::read_many() { } cheat::from_selection() { - local readonly cheats="$1" - local readonly selection="$2" + local -r cheats="$1" + local -r selection="$2" - local readonly tags="$(echo "$selection" | selection::tags)" + local -r tags="$(echo "$selection" | selection::tags)" for cheat in $cheats; do if grep -q "% $tags" "$cheat"; then diff --git a/src/main.sh b/src/main.sh index faf085e..45977cd 100644 --- a/src/main.sh +++ b/src/main.sh @@ -11,9 +11,9 @@ source "${SCRIPT_DIR}/src/str.sh" source "${SCRIPT_DIR}/src/ui.sh" handler::main() { - local readonly cheats="$(cheat::find)" - local readonly selection="$(ui::select "$cheats")" - local readonly cheat="$(cheat::from_selection "$cheats" "$selection")" + local -r cheats="$(cheat::find)" + local -r selection="$(ui::select "$cheats")" + local -r cheat="$(cheat::from_selection "$cheats" "$selection")" [ -z "$cheat" ] && exit 67 local cmd="$(selection::command "$selection" "$cheat")" local arg value @@ -34,7 +34,7 @@ handler::main() { cmd="$(echo "$cmd" | arg::interpolate "$arg" "$value")" done - local readonly unresolved_arg="$(echo "$cmd" | arg::next || echo "")" + local -r unresolved_arg="$(echo "$cmd" | arg::next || echo "")" if $print || [ -n "$unresolved_arg" ]; then echo "$cmd" @@ -44,9 +44,9 @@ handler::main() { } handler::preview() { - local readonly selection="$(echo "$query" | selection::standardize)" - local readonly cheats="$(cheat::find)" - local readonly cheat="$(cheat::from_selection "$cheats" "$selection")" + local -r selection="$(echo "$query" | selection::standardize)" + local -r cheats="$(cheat::find)" + local -r cheat="$(cheat::from_selection "$cheats" "$selection")" [ -n "$cheat" ] && selection::command "$selection" "$cheat" } diff --git a/src/opts.sh b/src/opts.sh index 04b218d..453998a 100644 --- a/src/opts.sh +++ b/src/opts.sh @@ -2,12 +2,12 @@ set -euo pipefail opts::extract_help() { - local readonly file="$1" + local -r file="$1" grep "^##?" "$file" | cut -c 5- } opts::preview_hack() { - local readonly arg="$1" + local -r arg="$1" if [ ${arg:0:1} = "'" ]; then echo "${arg:1:${#arg}-2}" @@ -17,7 +17,7 @@ opts::preview_hack() { } opts::eval() { - local readonly wait_for="" + local -r wait_for="" entry_point="main" print=false diff --git a/src/search.sh b/src/search.sh index 1b9bfbc..f611e0b 100644 --- a/src/search.sh +++ b/src/search.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash search::cheat() { - local readonly cmd="$(echo "$1" | str::first_word)" + local -r cmd="$(echo "$1" | str::first_word)" echo "% ${cmd}, cheatsh" echo @@ -9,7 +9,7 @@ search::cheat() { } search::filename() { - local readonly cmd="$(echo "$1" | str::first_word)" + local -r cmd="$(echo "$1" | str::first_word)" echo "${cmd}_cheatsh" \ | head -n1 \ @@ -19,16 +19,16 @@ search::filename() { } search::full_path() { - local readonly cmd="$(echo "$1" | str::first_word)" + local -r cmd="$(echo "$1" | str::first_word)" echo "/tmp/navi/$(search::filename "$cmd").cheat" } search::save() { - local readonly cmd="$(echo "$1" | str::first_word)" + local -r cmd="$(echo "$1" | str::first_word)" - local readonly filepath="$(search::full_path "$cmd")" - local readonly filedir="$(dirname "$filepath")" + local -r filepath="$(search::full_path "$cmd")" + local -r filedir="$(dirname "$filepath")" if [ -f "$filepath" ]; then return diff --git a/src/selection.sh b/src/selection.sh index 481df15..9f10ca8 100644 --- a/src/selection.sh +++ b/src/selection.sh @@ -1,10 +1,10 @@ #!/usr/bin/env bash selection::standardize() { - local readonly str="$(cat)" + local -r str="$(cat)" - local readonly tags="$(echo "$str" | awk -F'[' '{print $NF}' | tr -d ']')" - local readonly core="$(echo "$str" | sed -e "s/ \[${tags}\]$//")" + local -r tags="$(echo "$str" | awk -F'[' '{print $NF}' | tr -d ']')" + local -r core="$(echo "$str" | sed -e "s/ \[${tags}\]$//")" echo "${core}^${tags}" } @@ -22,10 +22,10 @@ selection::core_is_comment() { } selection::command() { - local readonly selection="$1" - local readonly cheat="$2" + local -r selection="$1" + local -r cheat="$2" - local readonly core="$(echo $selection | selection::core)" + local -r core="$(echo $selection | selection::core)" if echo "$core" | selection::core_is_comment; then grep "$core" "$cheat" -A999 \ diff --git a/src/str.sh b/src/str.sh index 6e860b6..f58e962 100644 --- a/src/str.sh +++ b/src/str.sh @@ -5,14 +5,14 @@ str::length() { } str::sub() { - local readonly start="${1:-0}" - local readonly finish="${2:-99999}" + local -r start="${1:-0}" + local -r finish="${2:-99999}" cut -c "$((start + 1))-$((finish - 1))" } str::column() { - local readonly n="${1:-}" + local -r n="${1:-}" if [ -n "$n" ]; then awk "{print \$$n}" diff --git a/src/ui.sh b/src/ui.sh index c8ab0a0..0cf8e7f 100644 --- a/src/ui.sh +++ b/src/ui.sh @@ -5,9 +5,9 @@ ui::pick() { } ui::select() { - local readonly cheats="$1" - local readonly script_path="$(which navi | head -n1 || echo "${SCRIPT_DIR}/navi")" - local readonly preview_cmd="echo \"{}\" | tr ' ' '^' | xargs -I% \"${script_path}\" preview %" + local -r cheats="$1" + local -r script_path="$(which navi | head -n1 || echo "${SCRIPT_DIR}/navi")" + local -r preview_cmd="echo \"{}\" | tr ' ' '^' | xargs -I% \"${script_path}\" preview %" local args=() args+=("-i")