Fix indentation (#8)

The code was indented using `dot code beautify`

Related: https://github.com/denisidoro/dotfiles
This commit is contained in:
Denis Isidoro 2019-09-20 20:08:13 -03:00 committed by GitHub
parent 0f2c95ce34
commit 1a111a97d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 122 additions and 122 deletions

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -2,5 +2,5 @@
# no-op hack to set dependency order resolution
dep() {
:
:
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}