Skip to content

Commit

Permalink
Improve script a bit
Browse files Browse the repository at this point in the history
Thanks shellcheck <3
  • Loading branch information
glumia committed Apr 16, 2022
1 parent 14cee2e commit 2b27b6b
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions bash-tiasft.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash
#
# bash-tiasft.sh -- Suggest shortcuts for aliased commands.
# https://github.com/glumia/bash-tiasft
#
Expand All @@ -7,7 +9,7 @@
#
# Author: Giuseppe Lumia (gius@glumia.dev)
#
# v0.1.2
# v0.1.3
#

# General Usage:
Expand All @@ -31,14 +33,15 @@ __aliases=$(alias)
# Take the command string and progressively search if there is an alias defined
# for it, removing the last word at each iteration.
function search_alias {
cmd=($*)
local cmd shortcut
IFS=" " read -ra cmd <<< "$1"
shortcut=""
while [[ -z "$shortcut" && -n "${cmd[*]}" ]]; do
shortcut=$(grep "[^=]*[\"\']${cmd[*]}[\'\"]" <<< "$__aliases")
unset cmd[${#cmd[@]}-1]
while [[ -z "${shortcut}" && "${#cmd[@]}" -gt 0 ]]; do
shortcut=$(grep "[^=]*[\"\']${cmd[*]}[\'\"]" <<< "${__aliases}")
unset "cmd[${#cmd[@]}-1]"
done
if [[ -n "$shortcut" ]]; then
printf "There is a shortcut for that!\n %s\n" "$shortcut"
if [[ -n "${shortcut}" ]]; then
printf "There is a shortcut for that!\n %s\n" "${shortcut}"
fi
}

Expand Down

0 comments on commit 2b27b6b

Please sign in to comment.