Xonsh the shell for XXIth century
Linux shell xonsh bash sh csh tcsh linux lazy
I am a happy user of xonsh shell, and let sh, csh, tcsh and bash behindβ¦
Xonsh merges python and shell, with a terrific prompt!
Discovering unix last century (hp-ux), i quickly enhanced my shell to tcsh. that included tab-completion and nice scripts! such a marvel compared to sh or csh.
Then came my first encounter with bash in linux: not a good memory. so i used to install tcsh on my box. except when i could notβ¦
Alas, always fighting to install a shell, i finally embraced the default bash. that lasted probably 20 years.
During those 20 years, things evolved (tab, color, hints, β¦) yet, the overall state did not change.
A new era of shell is coming. enter fish and xonsh (and more).
- before: 90% of my use of prompt: cd, ls, bc, cat, launchβ¦
- after: same, but all in python (no more bc)
xonsh
from xon.sh
xonsh is a python-powered, cross-platform, unix-gazing shell language and command prompt. the language is a superset of python 3.5+ with additional shell primitives that you are used to from bash and ipython. it works on all major systems including linux, mac osx, and windows. xonsh is meant for the daily use of experts and novices alike.
positive | slightly negative |
---|---|
Python from the console | slightly slow to start (on my old box) |
fantastic play with prompt (see below) | syntax for looping on files |
Xonsh prompt for the pleasure
Xonsh - start/stop
Details of .xonshrc
.xonshrc - Python code
# Update PROMPT with current time (every second)
import datetime
$MULTILINE_PROMPT = ''
$PROMPT_REFRESH_INTERVAL = 1
$UPDATE_PROMPT_ON_KEYPRESS = True
# SEEMS Very slow when "{branch_color}{curr_branch: {}}" in PROMPT...
DEFAULT_PROMPT = '\n{GREEN}ββ[%s] {RED}[{user}@{hostname}]' \
+ ' {BOLD_CYAN}[{cwd}]{NO_COLOR}\n{GREEN}ββ>{NO_COLOR} '
def update_prompt():
return(DEFAULT_PROMPT % datetime.datetime.now().strftime("%H:%M:%S"))
$PROMPT = update_prompt
# After command execution:
# - Update RIGHT_PROMPT with command duration (and more)
# - emphasize on error if RC != 0
@events.on_postcommand
def display_command_status(cmd, rtn, out, ts):
duration = ts[1] - ts[0]
if duration > 60:
$RIGHT_PROMPT = "\nπ %s " % str(datetime.timedelta(seconds=int(duration)))
elif duration > 0.2:
$RIGHT_PROMPT = "\nπ %.2fs " % duration
else:
$RIGHT_PROMPT = "\n<Ο> "
if rtn != 0:
$RIGHT_PROMPT = $RIGHT_PROMPT + "\nβ " + str(rtn) + " β "
print("\n" + "β " * 25)
print("β " + str(rtn))
if cmd[len(cmd)-1] == '\n':
cmd_p = cmd[0:len(cmd)-1]
else:
cmd_p = cmd
print("β " + cmd_p)
print("β " * 25 + "\n")
# Clean RIGHT_PROMPT when no command executed (Empty line, Enter/Enter)
$RIGHT_PROMPT = "Ο "
@events.on_post_prompt
def display_post_prompt():
$RIGHT_PROMPT = "Ο"