When I screenfetch with xonsh, python x.x comes out and it's sad

$ screenfetch
           /:-------------:\          user@host
        :-------------------::        OS: Fedora 30 Thirty
      :-----------/shhOHbmp---:\      Kernel: x86_64 Linux 5.3.16-200.fc30.x86_64
    /-----------omMMMNNNMMD  ---:     Uptime: 13h 27m
   :-----------sMMMMNMNMP.    ---:    Packages: 2531
  :-----------:MMMdP-------    ---\   Shell: python3.8
 ,------------:MMMd--------    ---:   Resolution: 1920x1080
 :------------:MMMd-------    .---:   DE: GNOME 
 :----    oNMMMMMMMMMNho     .----:   WM: GNOME Shell
 :--     .+shhhMMMmhhy++   .------/   WM Theme: Adwaita
 :-    -------:MMMd--------------:    GTK Theme: Adwaita [GTK2/3]
 :-   --------/MMMd-------------;     Icon Theme: Adwaita
 :-    ------/hMMMy------------:      Font: Cantarell 11
 :-- :dMNdhhdNMMNo------------;       CPU: Intel Core i7-8550U @ 8x 4GHz
 :---:sdNMMMMNds:------------:        GPU: Mesa DRI Intel(R) UHD Graphics 620 (Kabylake GT2) 
 :------:://:-------------::          RAM: 6817MiB / 15779MiB
 :---------------------://            

Shell: As you can see, it's a little sad. How does screenfetch take a shell in the first place? I thought, so I read it. If possible, please display Xonsh.

Read screenfetch

screenfetch:GitHub

screenfetch is a shell script ... scary Apparently screenfetch-dev is like the main body.

So, I want to know the shell relation, so Ctrl + F with shell.

Then, the detect shell () on the 1843 line from the yellow condition is suspicious.

Let's read it for the time being

The first half is shown for the time being.

detectshell () {
	if [[ ! "${shell_type}" ]]; then
		if [[ "${distro}" == "Cygwin" || "${distro}" == "Msys" || "${distro}" == "Haiku" || "${distro}" == "Alpine Linux" ||
			"${distro}" == "Mac OS X" || "${distro}" == "TinyCore" || "${distro}" == "Raspbian" || "${OSTYPE}" == "gnu" ]]; then
			shell_type=$(echo "$SHELL" | awk -F'/' '{print $NF}')
		elif readlink -f "$SHELL" 2>&1 | grep -q -i 'busybox'; then
			shell_type="BusyBox"
		else
			if [[ "${OSTYPE}" =~ "linux" ]]; then
				shell_type=$(tr '\0' '\n' </proc/$PPID/cmdline | head -1)
			elif [[ "${distro}" =~ "BSD" ]]; then
				shell_type=$(ps -p $PPID -o command | tail -1)
			else
				shell_type=$(ps -p "$(ps -p $PPID | awk '$1 !~ /PID/ {print $1}')" | awk 'FNR>1 {print $1}')
			fi
			shell_type=${shell_type/-}
			shell_type=${shell_type//*\/}
		fi
	fi

        .....

	myShell=${shell_type}
	verboseOut "Finding current shell...found as '$myShell'"
}

In fact, if you look at it with the -v option, you can see that the line verboseOut "Finding current shell ... found as'$ myShell'" is moving.

First, let's look inside the first if.

$ shell_type is like a variable of shell_type (like Shinjiro Koizumi). First of all, after looking at the type of OS, it seems that the shell is acquired according to the OS. Since the OS type is linux, let's see the block of ʻif [["$ {OSTYPE}" = ~ "linux"]] . By the way, = ~` seems to be a regular expression comparison. I just knew.

Well, as you can see, tr'\ 0''\ n'</ proc / $ PPID / cmdline | head -1 is the shell_type. I'm processing it a little behind, but it's later.

/ proc / $ PPPID / cmdline is a process command of $ PPPID, as you can guess from the name. I don't know what pid $ PPPID is, but it's probably a shell. Isn't it taken with some other code? Let's take a look.

$  ps
  PID TTY          TIME CMD
20316 pts/5    00:00:01 xonsh
21745 pts/5    00:00:00 ps

$  cat /proc/20316/cmdline                                                          
/home/tia/.pyenv/versions/3.8.1/bin/python3.8-u/home/tia/.pyenv/versions/3.8.1/bin/xonsh--login

Yes. Well as expected. I thought, but something is strange. python3.8-u ??? I thought this, but I looked at the right side. There is no space. why. whatever.

xonsh does not launch the xonsh binaries directly, it launches python. No, that's right. It's natural.

But, well, I somehow understood the cause. Since screenfetch gets the command that starts the shell and fetches the name of the shell, xonsh that starts python instead of the shell directly is seen as python instead of xonsh.

Let's take a look at the tr and head commands. Because I don't know.

... gg time ...

tr is the replacement of characters. str.replace (). ʻEcho hoge | tr'hoge''fuga'means'hoge'.replace ('hoge','fuga')`. In python

head fetches the specified line. str.splitlines (False) [n]. ʻEcho" hoge \ nfuga "| head -1means'hoge \ nfuga'.splitlines (False) [0]`.

So, the contents of cmdline are tr'\ 0''\ n'. Well, when I thought that the space was missing, it may be that there is \ 0 instead of the space. Well, do you know if you actually hit it?

$  tr '\0' '\n'  < /proc/20316/cmdline
/home/tia/.pyenv/versions/3.8.1/bin/python3.8
-u
/home/tia/.pyenv/versions/3.8.1/bin/xonsh
--login

Okay. Maybe it's like that. The line breaks are properly made.

And since it is head -1, the first line is taken out. That is, /home/tia/.pyenv/versions/3.8.1/bin/python3.8. It's completely this.

And finally

shell_type=${shell_type/-}
shell_type=${shell_type//*\/}

.. Maybe I'm taking out the rightmost of /.

Now you know the shell_type.

Well, the second half.


detectshell () {

        ......

	case $shell_type in
		bash)
			shell_version_data=$( detectshell_ver "$shell_type" "^GNU.bash,.version" "4" )
			;;
		BusyBox)
			shell_version_data=$( busybox | head -n1 | cut -d ' ' -f2 )
			;;
		csh)
			shell_version_data=$( detectshell_ver "$shell_type" "$shell_type" "3" )
			;;
		dash)
			shell_version_data=$( detectshell_ver "$shell_type" "$shell_type" "3" )
			;;
		ksh)
			shell_version_data=$( detectshell_ver "$shell_type" "version" "5" )
			;;
		tcsh)
			shell_version_data=$( detectshell_ver "$shell_type" "^tcsh" "2" )
			;;
		zsh)
			shell_version_data=$( detectshell_ver "$shell_type" "^zsh" "2" )
			;;
		fish)
			shell_version_data=$( fish --version | awk '{print $3}' )
			;;
	esac

	if [[ -n $shell_version_data ]];then
		shell_type="$shell_type $shell_version_data"
	fi

	myShell=${shell_type}
	verboseOut "Finding current shell...found as '$myShell'"
}

This is ... completely ignored. If $ shell_type is any of bash, BusyBox, csh, dash, ksh, tcsh, zsh, fish, it seems to read the version. Ignore Ignore.

Now, the conclusion is reached.

Since xonsh does not call bash directly like bash, but runs on python xonsh and python, the directly called pytohn is detected as a shell. that's all.

Countermeasures

Let's take a look at the first line of detectshell ().

detectshell () {
    if [[ ! "${shell_type}" ]]; then
...

Yes, first look to see if $ shell_type is already set. In other words, as a countermeasure

$ $shell_type = $(xonsh -V).strip()
$ screenfetch

that's all!

           /:-------------:\          user@host
        :-------------------::        OS: Fedora 30 Thirty
      :-----------/shhOHbmp---:\      Kernel: x86_64 Linux 5.3.16-200.fc30.x86_64
    /-----------omMMMNNNMMD  ---:     Uptime: 14h 28m
   :-----------sMMMMNMNMP.    ---:    Packages: 2531
  :-----------:MMMdP-------    ---\   Shell: xonsh/0.9.13.dev1
 ,------------:MMMd--------    ---:   Resolution: 1920x1080
 :------------:MMMd-------    .---:   DE: GNOME 
 :----    oNMMMMMMMMMNho     .----:   WM: GNOME Shell
 :--     .+shhhMMMmhhy++   .------/   WM Theme: Adwaita
 :-    -------:MMMd--------------:    GTK Theme: Adwaita [GTK2/3]
 :-   --------/MMMd-------------;     Icon Theme: Adwaita
 :-    ------/hMMMy------------:      Font: Cantarell 11
 :-- :dMNdhhdNMMNo------------;       CPU: Intel Core i7-8550U @ 8x 4GHz
 :---:sdNMMMMNds:------------:        GPU: Mesa DRI Intel(R) UHD Graphics 620 (Kabylake GT2) 
 :------:://:-------------::          RAM: 6954MiB / 15779MiB
 :---------------------://           
                       

Recommended Posts

When I screenfetch with xonsh, python x.x comes out and it's sad
I played with PyQt5 and Python3
I installed and used Numba with Python3.5
[Python] I introduced Word2Vec and played with it.
Recommended environment and usage when developing with Python
I tried Jacobian and partial differential with python
I tried function synthesis and curry with python
Three things I was addicted to when using Python and MySQL with Docker
I want to handle optimization with python and cplex
Findings when accelerating numerical calculations with Python and Numba
I checked out the versions of Blender and Python
I made a LINE BOT with Python and Heroku
When architecture not supported comes out with pip (Mac)
I implemented collaborative filtering (recommendation) with redis and python
I was surprised to receive a nice review when I wrote Python to CheckIO and its explanation
When I made CaboCha usable with python3, I got stuck (Windows 10)
I tried follow management with Twitter API and Python (easy)
I tried to make GUI tic-tac-toe with Python and Tkinter
This time I learned python III and IV with Prorate
I tried fp-growth with python
Programming with Python and Tkinter
I tried scraping with Python
Encryption and decryption with Python
Python and hardware-Using RS232C with Python-
I made blackjack with python!
# 2 [python3] Separation and comment out
I compared Java and Python!
Error when playing with python
python with pyenv and venv
I tried gRPC with Python
I tried scraping with python
I made blackjack with Python.
I made wordcloud with Python.
Works with Python and R
I compared the speed of Hash with Topaz, Ruby and Python
I made a simple circuit with Python (AND, OR, NOR, etc.)
I added Maki Horikita and Kanna Hashimoto and divided by 2 with python
I made a Nyanko tweet form with Python, Flask and Heroku
[Python] Error and solution memo when using venv with pyenv + anaconda
I tried to make a periodical process with Selenium and Python
I tried to find out if ReDoS is possible with Python
How to deal with errors when installing Python and pip with choco
Throw something to Kinesis with python and make sure it's in
I tried to easily detect facial landmarks with python and dlib