Add a check before running command and use glow to print markdown
Opened this issue · 1 comments
aemonge commented
Use this alias:
# default navi to print, not to execute
navi() {
if command navi --print "$@" > /tmp/navi_output; then
/usr/bin/glow /tmp/navi_output
else
echo "navi command failed" >&2
return 1
fi
}
_run_last_navi_or_builtin() {
if [ $# -gt 0 ]; then
# Use the built-in . (source) command if arguments are provided
builtin . "$@"
elif [ ! -s /tmp/navi_output ]; then
echo "No navi output found or file is empty. Run 'navi' command first." >&2
return 1
else
# Execute commands from navi output if no arguments
if ! /usr/bin/grep -q '^\$ ' /tmp/navi_output; then
echo "No executable commands found in navi output." >&2
return 1
fi
/usr/bin/grep '^\$ ' /tmp/navi_output | while read -r line; do
cmd="${line#\$ }"
echo "Executing: $cmd"
eval "$cmd"
done
fi
}
alias .="_run_last_navi_or_builtin"
With this you can use navi
to search for a comand , and if you want to run it just hit .
welcome commented
Thanks for opening your first issue here! In case you're facing a bug, please update navi to the latest version first. Maybe the bug is already solved! :)