Dec-26-2021, 08:39 PM
now i wish Python had a way to add commands. this would be particularly useful in interactive mode. the idea is that i would not need to type "()" just to run custom stuff in interactive mode.
def random(): return 'random stuff'If you would load/import such functions as above when working interactive. And somehow create variables or something.
a = custom()Like a said, it is not really added as a command, but maybe there is a way to further implement such functionality?
(Dec-26-2021, 08:56 PM)Jeff900 Wrote: [ -> ]maybe there is a way to further implement such functionality?
def boom(): exit('**** BOOM ****') __command_table__['die'] = boom diethat's just an overly simplistic example.
newcommands
. Then start the interactive interpreter with this:PYTHONSTARTUP=newcommands python3
. Then you can typec.die
orc.ls
orc.pwd
. Try it and then add all the commands you like.import os class Commands : @property def ls (self) : directory_list = os.listdir () for filename in directory_list : print (filename) @property def pwd (self) : print (os.getcwd()) @property def die (self) : exit () c = Commands () ''' c.ls c.pwd c.die '''
~/P/S/2021-12 import sys ~/P/S/2021-12 sys.executable '/usr/bin/python' ~/P/S/2021-12 echo "Hello xonsh!" Hello xonsh!
Output:lt2a/forums /home/forums 8> xonsh
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/xonsh/__amalgam__.py", line 20658, in main
return main_xonsh(args)
File "/usr/lib/python3/dist-packages/xonsh/__amalgam__.py", line 20682, in main_xonsh
print_welcome_screen()
File "/usr/lib/python3/dist-packages/xonsh/__amalgam__.py", line 14494, in print_welcome_screen
print_color(line)
File "/usr/lib/python3/dist-packages/xonsh/__amalgam__.py", line 5001, in print_color
builtins.__xonsh_shell__.shell.print_color(string, **kwargs)
File "/usr/lib/python3/dist-packages/xonsh/ptk/shell.py", line 273, in print_color
proxy_style = PygmentsStyle(pyghooks.xonsh_style_proxy(self.styler))
File "/usr/lib/python3/dist-packages/xonsh/pyghooks.py", line 476, in xonsh_style_proxy
class XonshStyleProxy(Style):
File "/usr/local/lib/python3.6/dist-packages/pygments/style.py", line 122, in __new__
ndef[0] = colorformat(styledef)
File "/usr/local/lib/python3.6/dist-packages/pygments/style.py", line 79, in colorformat
assert False, "wrong color format %r" % text
AssertionError: wrong color format '#ansidarkgreen'
Xonsh encountered an issue during launch
Failback to /bin/sh
\h/\u /home/forums \!>
\h/\u /home/forums \!> exit
lt2a/forums /home/forums 9>