-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a basic command plate to choose commands created by the current e…
…nv file
- Loading branch information
1 parent
771d29e
commit 2453358
Showing
3 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
_sherpa_command_plate() { | ||
local commands selected_command | ||
|
||
# shellcheck disable=SC2207 | ||
commands=( | ||
$(__sherpa_command_plate__load_local_aliases) | ||
$(__sherpa_command_plate__load_local_functions) | ||
) | ||
|
||
# Filter and sort the commands | ||
# shellcheck disable=SC2207 | ||
commands=( | ||
$( | ||
printf "%s\n" "${commands[@]}" | | ||
awk 'length >= 2' | # Remove short commands | ||
sort | ||
) | ||
) | ||
|
||
selected_command=$( | ||
printf "%s\n" "${commands[@]}" | | ||
fzf --layout=reverse \ | ||
--border \ | ||
--info=inline \ | ||
--margin=8,20 \ | ||
--padding=1 \ | ||
--cycle | ||
) | ||
|
||
if [ -n "$selected_command" ]; then | ||
echo "Running: $selected_command" | ||
eval "$selected_command" | ||
fi | ||
} | ||
|
||
__sherpa_command_plate__load_local_aliases() { | ||
unalias -a | ||
|
||
# shellcheck disable=SC1090 | ||
source "$SHERPA_ENV_FILENAME" &> /dev/null | ||
|
||
compgen -a | ||
} | ||
|
||
__sherpa_command_plate__load_local_functions() { | ||
local -r filter_pattern="^[[:space:]]*([[:alnum:]_]+[[:space:]]*\(\)|function[[:space:]]+[[:alnum:]_]+)" | ||
|
||
# Cleanup: | ||
# "function_1()" -> "function_1" | ||
# "function function_2()" -> "function_2()" -> "function_2" | ||
grep -oE "$filter_pattern" "$SHERPA_ENV_FILENAME" | | ||
sed "s/function //" | | ||
sed "s/()//" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters