fix KittyKatt#632 and KittyKatt#606
Hi,
I created patches for the fix for Cygwin, MSYS2 and Git Bash.
You can test the patched version in your environment with the following command.
curl -sL https://github.com/yanorei32/screenFetch/raw/msys-cygwin-patch-combined/screenfetch-dev | bash
Those unexpected behaviours mostly come from line-terminating format compatibility issues between Windows and *NIX utilities. They are fixable with a small patch.
Platform | Actual behaviour | Expected behaviour |
---|---|---|
Cygwin | OS and WM Theme are broken. |
|
MSYS2 | WM Theme is broken. |
|
Git Bash | Packages †1 and WM Theme are broken. |
†1: It's not a line-terminating format issue.
Cygwin is mostly UNIX compatible. MSYS2 is just a UNIX-like development environment for Windows development. Git for Bash is like MSYS2, but this environment is developed only for git.
The difference in development motivation between Cygwin, MSYS2 and Git for Bash makes the problem more complicated.
The OS
column implementation is here.
This code calls WMIC repeatedly. WMIC outputs CRCRLF (0d 0d 0a) style line-terminate †2.
†2: Sorry, I don't know why this output already misconvert to CRCRLF (0d 0d 0a) from CRLF (0d 0a).
$ wmic os get version
Version
10.0.22621
$ wmic os get version | xxd -g 1
00000000: 56 65 72 73 69 6f 6e 20 20 20 20 20 0d 0d 0a 31 Version ...1
00000010: 30 2e 30 2e 32 32 36 32 31 20 20 0d 0d 0a 0d 0d 0.0.22621 .....
00000020: 0a .
$ wmic os get version | grep '^10\.' | xxd -g 1
00000000: 31 30 2e 30 2e 32 32 36 32 31 20 20 0d 0d 0a 10.0.22621 ...
$ wmic os get version | grep '^10\.' | tr -d ' ' | xxd -g 1
00000000: 31 30 2e 30 2e 32 32 36 32 31 0d 0d 0a 10.0.22621...
$ uname -a
CYGWIN_NT-10.0-22621 DESKTOP-5H6F7L3 3.4.0-341.x86_64 2022-02-13 03:22 UTC x86_64 Cygwin
$
Unfortunately, CR are still in the output. It's not good. Your terminal starts carriage return (CR) and shows remaining ")" + $sysArch.
The patch for this problem just added the CR filter | tr -d "\r"
.
elif [[ "$distro" == "Cygwin" || "$distro" == "Msys" ]]; then
distro="$(wmic os get caption | sed 's/\r//g; s/[ \t]*$//g; 2!d')"
if [[ "$(wmic os get version | grep -o '^10\.')" == "10." ]]; then
- distro="$distro (v$(wmic os get version | grep '^10\.' | tr -d ' '))"
+ distro="$distro (v$(wmic os get version | tr -d "\r" | grep '^10\.' | tr -d ' '))"
fi
sysArch=$(wmic os get OSArchitecture | sed 's/\r//g; s/[ \t]*$//g; 2!d')
mydistro=$(echo -e "$labelcolor OS:$textcolor $distro $sysArch")
Because, MSYS grep converts implicity any CRLF (0d0a) and CRs+LF (many 0d + 0a) to LF (0a).
In MSYS (CR is filtered by grep):
$ echo -en "\r\n" | xxd -g1
00000000: 0d 0a ..
$ echo -en "\r\n" | grep "" | xxd
00000000: 0a .
$ echo -en "\r\r\n" | grep "" | xxd
00000000: 0a .
$ echo -en "\r\r\r\n" | grep "" | xxd
00000000: 0a .
$
In Cygwin and more standard Linux distributions (CR is not filtered by grep):
$ echo -en "\r\n" | xxd -g1
00000000: 0d 0a ..
$ echo -en "\r\n" | grep "" | xxd -g1
00000000: 0d 0a ..
$ echo -en "\r\r\n" | grep "" | xxd -g1
00000000: 0d 0d 0a ...
$ echo -en "\r\r\r\n" | grep "" | xxd -g1
00000000: 0d 0d 0d 0a ....
$
I think the behaviour makes comfortable the development with the Windows toolchains. Is the patch compatible? Yes, that is the just filter of CR (0d), and in this case, that takes no effect.
The WM Theme
column implementation is here.
This issue is very similar to the OS
column issue. MSYS sed converts CRLF to LF too.
This problem can fix with insertion | tr -d "\r"
to two lines.
elif [[ "${distro}" == "Cygwin" || "${distro}" == "Msys" ]]; then
if [ "${WM}" == "Blackbox" ]; then
if [ "${distro}" == "Msys" ]; then
Blackbox_loc=$(reg query 'HKLM\Software\Microsoft\Windows NT\CurrentVersion\WinLogon' //v 'Shell')
else
Blackbox_loc=$(reg query 'HKLM\Software\Microsoft\Windows NT\CurrentVersion\WinLogon' /v 'Shell')
fi
- Blackbox_loc="$(echo "${Blackbox_loc}" | sed 's/.*REG_SZ//' | sed -e 's/^[ \t]*//' | sed 's/.\{4\}$//')"
+ Blackbox_loc="$(echo "${Blackbox_loc}" | tr -d "\r" | sed 's/.*REG_SZ//' | sed -e 's/^[ \t]*//' | sed 's/.\{4\}$//')"
Win_theme=$(grep 'session.styleFile' "${Blackbox_loc}.rc" | sed 's/ //g' | sed 's/session\.styleFile:https://g' | sed 's/.*\\//g')
else
if [[ "${distro}" == "Msys" ]]; then
themeFile="$(reg query 'HKCU\Software\Microsoft\Windows\CurrentVersion\Themes' //v 'CurrentTheme')"
else
themeFile="$(reg query 'HKCU\Software\Microsoft\Windows\CurrentVersion\Themes' /v 'CurrentTheme')"
fi
- Win_theme=$(echo "$themeFile" | awk -F"\\" '{print $NF}' | sed 's|\.theme$||')
+ Win_theme=$(echo "$themeFile" | tr -d "\r" | awk -F"\\" '{print $NF}' | sed 's|\.theme$||')
fi
else
Its simple bug can fix with | grep CurrentTheme
.
if [[ "${distro}" == "Msys" ]]; then
themeFile="$(reg query 'HKCU\Software\Microsoft\Windows\CurrentVersion\Themes' //v 'CurrentTheme')"
else
themeFile="$(reg query 'HKCU\Software\Microsoft\Windows\CurrentVersion\Themes' /v 'CurrentTheme')"
fi
- Win_theme=$(echo "$themeFile" | tr -d "\r" | awk -F"\\" '{print $NF}' | sed 's|\.theme$||')
+ Win_theme=$(echo "$themeFile" | tr -d "\r" | grep CurrentTheme | awk -F"\\" '{print $NF}' | sed 's|\.theme$||')
$ reg query 'HKCU\Software\Microsoft\Windows\CurrentVersion\Themes' /v 'CurrentTheme'
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes
CurrentTheme REG_SZ C:\Windows\resources\Themes\dark.theme
$ reg query 'HKCU\Software\Microsoft\Windows\CurrentVersion\Themes' /v 'CurrentTheme' | grep CurrentTheme
CurrentTheme REG_SZ C:\Windows\resources\Themes\dark.theme
$
The Packages
column implementation is here.
KittyKatt/screenfetch detects Git for Windows as MSYS.
The packages routine will go to Msys if-branch, but Git for Windows does not have any package manager. (Because this environment only for git.)
'Msys')
- pkgs=$(pacman -Qq | wc -l)
- if [ -d "/c/ProgramData/chocolatey/lib" ]; then
- chocopkgs=$(ls -1 /c/ProgramData/chocolatey/lib | wc -l)
- pkgs=$((pkgs + chocopkgs))
+ # Git for Windows (Msys-based) does not have any package manager
+ if command -v pacman &> /dev/null; then
+ # for Msys
+ pkgs=$(pacman -Qq | wc -l)
+ if [ -d "/c/ProgramData/chocolatey/lib" ]; then
+ chocopkgs=$(ls -1 /c/ProgramData/chocolatey/lib | wc -l)
+ pkgs=$((pkgs + chocopkgs))
+ fi
+ else
+ # for Git for Windows
+ if [ -d "/c/ProgramData/chocolatey/lib" ]; then
+ chocopkgs=$(ls -1 /c/ProgramData/chocolatey/lib | wc -l)
+ pkgs="$pkgs + $chocopkgs" # shows "Unknown + 1234"
+ fi
fi
I'll send two pull-request one for CRLF and simple bugfix and one for Git for windows pacman related bugfix.
I hope these problems are resolved early.
Thanks,
screenFetch is a "Bash Screenshot Information Tool". This handy Bash script can be used to generate one of those nifty terminal theme information + ASCII distribution logos you see in everyone's screenshots nowadays. It will auto-detect your distribution and display an ASCII version of that distribution's logo and some valuable information to the right. There are options to specify no ASCII art, colors, taking a screenshot upon displaying info, and even customizing the screenshot command! This script is very easy to add to and can easily be extended.
Please see Installation.
To run screenFetch, open a terminal of some sort and type in the command screenfetch
or wherever you saved the script to. This will generate an ASCII logo with the
information printed to the side of the logo. There are some options that may be
specified on the command line, and those are shown below or by executing screenfetch -h
:
-v Verbose output.
-o 'OPTIONS' Allows for setting script variables on the
command line. Must be in the following format...
'OPTION1="OPTIONARG1";OPTION2="OPTIONARG2"'
-d '+var;-var;var' Allows for setting what information is displayed
on the command line. You can add displays with +var,var. You
can delete displays with -var,var. Setting without + or - will
set display to that explicit combination. Add and delete statements
may be used in conjunction by placing a ; between them as so:
+var,var,var;-var,var.
-n Do not display ASCII distribution logo.
-N Strip all color from output.
-w Wrap long lines.
-t Truncate output based on terminal width (Experimental!).
-p Output in portrait mode, with logo above info.
-s [-u IMGHOST] Using this flag tells the script that you want it
to take a screenshot. Use the -m flag if you would like
to move it to a new location afterwards.
-c string You may change the outputted colors with -c. The format is
as follows: [0-9][0-9],[0-9][0-9]. The first argument controls the
ASCII logo colors and the label colors. The second argument
controls the colors of the information found. One argument may be
used without the other.
-a 'PATH' You can specify a custom ASCII art by passing the path
to a Bash script, defining `startline` and `fulloutput`
variables, and optionally `labelcolor` and `textcolor`.
See the `asciiText` function in the source code for more
information on the variables format.
-S 'COMMAND' Here you can specify a custom screenshot command for
the script to execute. Surrounding quotes are required.
-D 'DISTRO' Here you can specify your distribution for the script
to use. Surrounding quotes are required.
-A 'DISTRO' Here you can specify the distribution art that you want
displayed. This is for when you want your distro
detected but want to display a different logo.
-E Suppress output of errors.
-C Add custom (extra) lines.
For example:
screenfetch -C 'IP WAN=192.168.0.12,IP BRIDGED=10.1.1.10'
... will add two extra lines:
IP WAN: 192.168.0.12
IP BRIDGED: 10.1.1.10
-V, --version Display current script version.
-h, --help Display this help.
If you would like to suggest something new, inform me of an issue in the
script, become part of the project, or talk to me about anything else,
you can either email me at [email protected]
or you can connect
to Rizon and reach me at irc:https://irc.rizon.net/screenFetch