[Xonsh] The Python shell is sharp and god

I've seen some shells as part of the modification of the Mac terminal environment. bash, zsh, fish ...

Especially for the last six months, I've loved Python-made Xonsh, so I'll introduce it to myself.

By the way, the reason I found the original story was the blog of Mr. Bankushi, who is famous in the machine learning area.

Summary of impressions and environment settings using Python shell xonsh for half a year

This person is too amazing What's Xonsh

It's just the title, but it's ** Shell ** made in Python. ** Made in Python, works in Python and can run Python. ** **

I don't know why the other shells are working, but anyway, this one is super sharp and cool.

Commnd and Python One of the advantages of being made with Python is that commands and Python scripts can live together.

 [ ~/Desktop/tmp ]                                                                                                                                                                
$ ls -al                                                                                                                                                                          
Permissions Size User Date Modified Name
drwxr-xr-x     - *** 18 12 19:20   .
drwx------     - *** 18 12 19:18   ..
 [ ~/Desktop/tmp ]                                                                                                                                                                
$ dirs = ['a', 'b', 'c']                                                                                                                                                          
 [ ~/Desktop/tmp ]                                                                                                                                                                
$ for dir in dirs: 
.     mkdir @(dir) 
.                                                                                                                                                                                 
 [ ~/Desktop/tmp ]                                                                                                                                                                
$ ls -al                                                                                                                                                                          
Permissions Size User Date Modified Name
drwxr-xr-x     - *** 18 12 19:21   .
drwx------     - *** 18 12 19:18   ..
drwxr-xr-x     - *** 18 12 19:21   a
drwxr-xr-x     - *** 18 12 19:21   b
drwxr-xr-x     - *** 18 12 19:21   c

Like this. Mkdir x 3 is better than putting it in a variable and turning the for statement! !! You might think, Don't you think it's really cool if you use this when the processing has increased a lot?

As a matter of course, you can even define a function.

 [ ~/Desktop/tmp ]                                                                                                                                                                
$ def hello_xonsh(): 
.     print('hello xonsh !!!') 
.                                                                                                                                                                                 
 [ ~/Desktop/tmp ]                                                                                                                                                                
$ hello_xonsh()                                                                                                                                                                   
hello xonsh !!!

.xonshrc Like other shells, xonsh has an rc file. (.Xonshrc) As you can imagine, this rc file can all be written in Python.

** Personally, this is too god to use **

aliases['ls'] = 'exa -ahl --git'
aliases['la'] = 'exa -ahl --git'
aliases['ll'] = 'exa -ahl --git'
aliases['l'] = 'exa -ahl --git'
aliases['cat'] = 'bat'
aliases['tf'] = 'terraform'
aliases['do'] = 'docker'
aliases['dc'] = 'docker-compose'

A dictionary type variable called aliases is defined internally and added to it. too cool.

import os
$DEV_ROOT = os.environ.get('HOME') + '/dev'

Environment variables are defined by $ + variable name. If you import it, you can use the standard Python library as much as you want.

def _set_aws_profile(args):
    $AWS_PROFILE = args[0]
    $AWS_DEFAULT_PROFILE = args[0]
    print('aws profile is : ', p)
aliases['awsp'] = _set_aws_profile

Complex commands can be defined by functions and put into aliases as they are. You can receive command arguments with the args argument.

By the way, only args is defined here, but it seems that stdin and stdout can also be taken. (I haven't mastered it well here)

Install If you read this far and want to use it, install is a moment.

$ brew install xonsh

Or

$ pip install xonsh

And so on, it can be installed in most other environments.

Start up is that way

$ xonsh

Use Xonsh! Xonsh has some disadvantages because it is sharp. For example, depending on the command, there were times when it wouldn't work unless the arguments were well enclosed in single quotes.

However, I use it because it is a good condition that far exceeds such a small disadvantage.

If you like Python, give it a try! !!

Recommended Posts

[Xonsh] The Python shell is sharp and god
The answer of "1/2" is different between python2 and 3
About the difference between "==" and "is" in python
[Python] Python and security-① What is Python?
Identity and equivalence Python is and ==
The story of Python and the story of NaN
Difference between == and is in python
[Python] What is @? (About the decorator)
[python] What is the sorted key?
What is the python underscore (_) for?
Python: Update pyenv without thinking and solve the "where is Python?" Phenomenon
Write a script in Shell and Python to notify you in Slack when the process is finished
[Python] What is pandas Series and DataFrame?
[Introduction to Python] What is the difference between a list and a tuple?
Where is the python instantiation process written?
What is "mahjong" in the Python library? ??
[python] [meta] Is the type of python a type?
Easily graph data in shell and Python
Academia Potter and the Mysterious Python Pass
How to use is and == in Python
Python open and io.open are the same
Made good with Python and xonsh so that you can see EC2 instances just by entering the shell
What is the difference between `pip` and` conda`?
What is "functional programming" and "object-oriented" in Python?
Summary of the differences between PHP and Python
What is wheezy in the Docker Python image?
ffmpeg-Build a python environment and split the video
Wagtail is the best CMS for Python! (Perhaps)
Specifying the range of ruby and python arrays
Compare the speed of Python append and map
This is the only basic review of Python ~ 1 ~
This is the only basic review of Python ~ 2 ~
What are you comparing with Python is and ==?
Solving the Lorenz 96 model with Julia and Python
Archive and compress the entire directory with python
Launch a shell while a Python script is running
This is the only basic review of Python ~ 3 ~
About the * (asterisk) argument of python (and itertools.starmap)
A discussion of the strengths and weaknesses of Python
What is the difference between Unix and Linux?
Python is easy
What is python
The timing when the value of the default argument is evaluated is different between Ruby and Python.
Python is instance
It is easy to execute SQL with Python and output the result in Excel
the shell review
What is Python
Check if the string is a number in python
The simplest Python memo in Japan (classes and objects)
Receive the form in Python and do various things
[Python] Measures and displays the time required for processing
The process of installing Atom and getting Python running
Python --Explanation and usage summary of the top 24 packages
Python3 datetime is faster just by specifying the timezone
Carefully understand the exponential distribution and draw in Python
Is the Python 3 Engineer Certification Basic Exam Really Easy?
What is the difference between usleep, nanosleep and clock_nanosleep?
Indent behavior of json.dumps is different between python2 and python3
Visualize the range of interpolation and extrapolation with python
Plot and understand the multivariate normal distribution in Python
Referencing and changing the upper bound of Python recursion