Created
April 28, 2025 00:00
-
-
Save tangentstorm/9651953dbc9450da601a7e730e1cbd8a to your computer and use it in GitHub Desktop.
evaluate j syntax directly in zsh prompt
This file contains hidden or 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
# Reset color after command execution | |
preexec() { | |
echo -ne "\e[0m" | |
} | |
# J language interceptor using ZLE | |
j-line-intercept() { | |
local cmd="$BUFFER" | |
if [[ "$cmd" = "j "* ]]; then | |
local j_code="${cmd#j }" | |
BUFFER="" | |
zle accept-line | |
print -s "j $j_code" | |
preexec # <- defined earlier to reset color | |
echo "\n\n $j_code" | |
echo "$j_code" | /Applications/j9.4/bin/jconsole | |
else | |
zle .accept-line | |
fi | |
} | |
# Create the ZLE widget | |
zle -N accept-line j-line-intercept | |
# Plain function for when j is called directly | |
j() { | |
if [ $# -eq 0 ]; then | |
# If no arguments, just run interactive jconsole | |
/Applications/j9.4/bin/jconsole | |
else | |
echo -ne "\e[0m" | |
echo "\n\n $*" | |
echo "$*" | /Applications/j9.4/bin/jconsole | |
fi | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment