From 7f2bcdc1b169bcf8a4676e86cabfded3a29de386 Mon Sep 17 00:00:00 2001 From: Patrick Wu Date: Fri, 30 Dec 2022 18:56:38 +0800 Subject: [PATCH 01/22] Update VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 7096a11f..00cf9325 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.1.0-1 +4.1.1-1 From a5cba04290822ed0796ce4bd55bef772d0e9825c Mon Sep 17 00:00:00 2001 From: iskandarma Date: Thu, 12 Jan 2023 00:12:00 +0800 Subject: [PATCH 02/22] bugfix: sysdrive_prefix returning wrong label when Windows installed at label other than C: --- src/wslu-header | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/wslu-header b/src/wslu-header index 5f339250..a1e75c97 100644 --- a/src/wslu-header +++ b/src/wslu-header @@ -206,14 +206,13 @@ function interop_prefix { } function sysdrive_prefix { - win_location="$(interop_prefix)" hard_reset=0 - for pt in "$win_location"/*; do + for pt in "$(interop_prefix)"/*; do [[ -e "$pt" ]] || break if [ "$(echo "$pt" | wc -l)" -eq 1 ]; then - if [ -d "$win_location$pt/Windows/System32" ]; then + if [ -d "$pt/Windows/System32" ]; then hard_reset=1 - win_location="$pt" + win_location="$(echo "$pt" | sed -e 's,^'"$(interop_prefix)"'/,,')" break fi fi From 1c2e96334c290090d63e0ead00400288a77fadc2 Mon Sep 17 00:00:00 2001 From: iskandarma Date: Tue, 24 Jan 2023 23:25:11 +0800 Subject: [PATCH 03/22] replace `sed` with simple `basename` --- src/wslu-header | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wslu-header b/src/wslu-header index a1e75c97..e4e695ea 100644 --- a/src/wslu-header +++ b/src/wslu-header @@ -212,7 +212,7 @@ function sysdrive_prefix { if [ "$(echo "$pt" | wc -l)" -eq 1 ]; then if [ -d "$pt/Windows/System32" ]; then hard_reset=1 - win_location="$(echo "$pt" | sed -e 's,^'"$(interop_prefix)"'/,,')" + win_location="$(basename "$pt")" break fi fi From f68117f69e4e4dfc00029319ec3f8f87425a4bb2 Mon Sep 17 00:00:00 2001 From: Charlie Jones Date: Tue, 14 Mar 2023 15:13:23 -0500 Subject: [PATCH 04/22] Add support for Rocky to installer --- extras/scripts/wslu-install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/scripts/wslu-install b/extras/scripts/wslu-install index ad82d3e5..82cdeba4 100644 --- a/extras/scripts/wslu-install +++ b/extras/scripts/wslu-install @@ -24,7 +24,7 @@ case $distro in Alpine*) sudo apk add git;; Arch*) sudo pacman -Syyu git --noconfirm;; Scientific*) sudo yum install -y git;; - *Fedora*) sudo dnf install -y git;; + *Fedora*|*Rocky*) sudo dnf install -y git;; *Gentoo*) sudo emerge -a n dev-vcs/git;; *Generic*) [ "fedora" == "$(cat /etc/os-release | grep -e "LIKE=" | sed -e 's/ID_LIKE=//g')" ] && sudo dnf install -y git || exit 1;; *) exit 1;; From 7e976b8a939d82ac009a33a74e76ee022a117396 Mon Sep 17 00:00:00 2001 From: kbpk Date: Wed, 22 Mar 2023 02:26:20 +0100 Subject: [PATCH 05/22] wslact: fix memory-reclaim incoherence --- docs/wslact.1 | 8 ++++---- src/wslact.sh | 2 +- tests/wslact.bats | 26 +++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/docs/wslact.1 b/docs/wslact.1 index 4fc59254..659dce82 100644 --- a/docs/wslact.1 +++ b/docs/wslact.1 @@ -14,7 +14,7 @@ Currently, we have two features available: .nf \fBts, time-sync\fR \- Time Sync \fBam, auto-mount\fR \- Auto Mounting -\fBmr, mem-reclaim\fR \- Memory Reclaimation +\fBmr, memory-reclaim\fR \- Memory Reclamation .fi .in .SH COMMANDS @@ -52,11 +52,11 @@ pass a list of options you want to pass to \fImount\fR command. print a simple help. .in .fi -.SS "Memory Reclaimation" -Memory Reclaimation (\fImem-reclaim\fR) feature allows you to reclaim memory by dropping memory cache. Requires sudo. +.SS "Memory Reclamation" +Memory Reclamation (\fImemory-reclaim\fR) feature allows you to reclaim memory by dropping memory cache. Requires sudo. .TP SYNOPSIS -.B wslact auto-mount +.B wslact memory-reclaim .RB [ \-h ] .TP OPTIONS diff --git a/src/wslact.sh b/src/wslact.sh index 59e8a9c4..1060bea3 100644 --- a/src/wslact.sh +++ b/src/wslact.sh @@ -101,7 +101,7 @@ while [ "$1" != "" ]; do case "$1" in ts|time-sync|tr|time-reset) time_reset "$@"; exit;; am|auto-mount|sm|smart-mount) auto_mount "$@"; exit;; - mr|mem-reclaim) memory_reclaim "$@"; exit;; + mr|memory-reclaim|mem-reclaim) memory_reclaim "$@"; exit;; -h|--help) help "$0" "$help_short"; exit;; -v|--version) version; exit;; *) error_echo "Invalid Input. Aborted." 22;; diff --git a/tests/wslact.bats b/tests/wslact.bats index b8b39a61..b880224d 100644 --- a/tests/wslact.bats +++ b/tests/wslact.bats @@ -59,4 +59,28 @@ run out/wslact am -h [ "${lines[0]}" = "wslact - Part of wslu, a collection of utilities for Linux Subsystem for Windows (WSL)" ] [ "${lines[1]}" = "Usage: wslact auto-mount [-mh]" ] -} \ No newline at end of file +} + +@test "wslact - Memory Reclamation - Help" { + run out/wslact memory-reclaim --help + [ "${lines[0]}" = "wslact - Part of wslu, a collection of utilities for Linux Subsystem for Windows (WSL)" ] + [ "${lines[1]}" = "Usage: wslact memory-reclaim [-h]" ] +} + +@test "wslact - Memory Reclamation - Help - Alt." { + run out/wslact memory-reclaim -h + [ "${lines[0]}" = "wslact - Part of wslu, a collection of utilities for Linux Subsystem for Windows (WSL)" ] + [ "${lines[1]}" = "Usage: wslact memory-reclaim [-h]" ] +} + +@test "wslact - Memory Reclamation - short form - Help" { + run out/wslact mr --help + [ "${lines[0]}" = "wslact - Part of wslu, a collection of utilities for Linux Subsystem for Windows (WSL)" ] + [ "${lines[1]}" = "Usage: wslact memory-reclaim [-h]" ] +} + +@test "wslact - Memory Reclamation - short form - Help - Alt." { + run out/wslact mr -h + [ "${lines[0]}" = "wslact - Part of wslu, a collection of utilities for Linux Subsystem for Windows (WSL)" ] + [ "${lines[1]}" = "Usage: wslact memory-reclaim [-h]" ] +} From 2cd6c5db61cb67e19488d0c253dfa11cc94859b6 Mon Sep 17 00:00:00 2001 From: kbpk Date: Wed, 22 Mar 2023 02:43:35 +0100 Subject: [PATCH 06/22] wslact: increase memory reclamation amount --- src/wslact.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wslact.sh b/src/wslact.sh index 1060bea3..4865df2d 100644 --- a/src/wslact.sh +++ b/src/wslact.sh @@ -93,6 +93,7 @@ function memory_reclaim { error_echo "\`wslact memory-reclaim\` requires you to run as root. Aborted." 1 fi + sync echo 1 > /proc/sys/vm/drop_caches echo "${info} Memory Reclaimed." } From b19df3d9ee311c3f82846af0c0be2ce7f4def201 Mon Sep 17 00:00:00 2001 From: Carlos Rafael Ramirez Date: Mon, 3 Jul 2023 22:47:10 +0200 Subject: [PATCH 07/22] Deploy to Pengwin debian bookworm as well --- .github/workflows/pkgdeploy.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pkgdeploy.yaml b/.github/workflows/pkgdeploy.yaml index 9edb2b9b..8fa4defb 100644 --- a/.github/workflows/pkgdeploy.yaml +++ b/.github/workflows/pkgdeploy.yaml @@ -54,10 +54,14 @@ jobs: with: name: PengwinDEBs - run: gem install package_cloud - - name: deploy to the dev + - name: deploy to bullseye repo env: PACKAGECLOUD_TOKEN: ${{ secrets.PGW_DEV_DEPLOY_KEY }} run: package_cloud push whitewaterfoundry/wslu/debian/bullseye ./PengwinDEBs/*.deb --skip-errors + - name: deploy to bookworm + env: + PACKAGECLOUD_TOKEN: ${{ secrets.PGW_DEV_DEPLOY_KEY }} + run: package_cloud push whitewaterfoundry/wslu/debian/bookworm ./PengwinDEBs/*.deb --skip-errors rpmobsbuild: name: RPM - OpenSUSE Build Service runs-on: ubuntu-20.04 From db7c574e537b90eb1ce26016f57dff3e30735772 Mon Sep 17 00:00:00 2001 From: Muhammad Imaduddin Date: Fri, 22 Sep 2023 09:54:57 +0700 Subject: [PATCH 08/22] wslview: fix opening links with brackets curl treats brackets as special glob characters, but powershell does not have that same behavior so it should be better to turn off curl globbing. --- src/wslview.sh | 2 +- tests/wslview.bats | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/wslview.sh b/src/wslview.sh index 9699ae16..1c26d494 100644 --- a/src/wslview.sh +++ b/src/wslview.sh @@ -25,7 +25,7 @@ function add_reg_alt { } function url_validator { - content=$(curl --head --silent "$*" | head -n 1) + content=$(curl --head --silent -g "$*" | head -n 1) if [ -n "$content" ]; then return 0 else diff --git a/tests/wslview.bats b/tests/wslview.bats index 99a1b297..f6a22285 100644 --- a/tests/wslview.bats +++ b/tests/wslview.bats @@ -95,3 +95,8 @@ setup() { run out/wslview "https://wslutiliti.es/" [ "$status" -eq 0 ] } + +@test "wslview - Internet - with brackets" { + run out/wslview "https://www.duckduckgo.com/?q=[wslu]" + [ "$status" -eq 0 ] +} From e4aecb3c0a79dcb3c0d12c00aaa5b28adac7e468 Mon Sep 17 00:00:00 2001 From: Smoothieewastaken Date: Fri, 27 Oct 2023 13:31:56 +0545 Subject: [PATCH 09/22] docs:fixed typos --- docs/wslfetch.1 | 2 +- docs/wslgsu.1 | 2 +- docs/wslsys.1 | 4 ++-- docs/wslu.7 | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/wslfetch.1 b/docs/wslfetch.1 index 8b9d2dbf..6998a115 100644 --- a/docs/wslfetch.1 +++ b/docs/wslfetch.1 @@ -26,7 +26,7 @@ add a colorbar to the printed information. This can also be set with the configu Force to print information with generic WSL logo. .TP .B -t, --theme \fITHEME\fR -set a cutom theme from the file \fITHEME\fR. This can also be set with the configuration \fIWSLFETCH_THEME_PATH\fR. +set a custom theme from the file \fITHEME\fR. This can also be set with the configuration \fIWSLFETCH_THEME_PATH\fR. .TP .B -o, --options \fIOPTIONS\fR set custom options from the file \fIOPTIONS\fR. Please refer to the WSLFETCH_INFO_SECTION in the CONFIGURATION section for more information. diff --git a/docs/wslgsu.1 b/docs/wslgsu.1 index fe8c7a96..60be5b9e 100644 --- a/docs/wslgsu.1 +++ b/docs/wslgsu.1 @@ -27,7 +27,7 @@ Print current version. Use a separate user to execute the command/service. By default it's \fIroot\fR. .TP .B -n, --name \fINAME\fR -Add an explicit name instead of the default of autoamtically extracting a name from the service/command. +Add an explicit name instead of the default of automatically extracting a name from the service/command. .TP .B -S, --service Using this option means you are addng a system service. without \fB-S\fR, you are adding a command to system. diff --git a/docs/wslsys.1 b/docs/wslsys.1 index 3b40a5ef..acd3f92d 100644 --- a/docs/wslsys.1 +++ b/docs/wslsys.1 @@ -38,7 +38,7 @@ For example, \fB"0x5df84068"\fR. .TP .B -b, --branch Print current release branch of your Windows 10. -For example, \fB"rs_prerelease"\fR means you are on rs_prerelease realease branch. +For example, \fB"rs_prerelease"\fR means you are on rs_prerelease release branch. .TP .B -B, --build Print current build version of your Windows 10. @@ -73,7 +73,7 @@ Print the current IPv4 address for your WSL distro. For example, \fB"127.37.41.23"\fR. .TP .B -S, --display-scaling -Print the current disply scaling from your display setting. +Print the current display scaling from your display setting. For example, \fB"2"\fR for 200% scaling. .TP .B -l, --locale diff --git a/docs/wslu.7 b/docs/wslu.7 index a8c18cca..464fa381 100644 --- a/docs/wslu.7 +++ b/docs/wslu.7 @@ -45,7 +45,7 @@ Entering debug mode. Entering verbose mode. .SH CONFIGURATION .TP -The defualt configuration is stored in /usr/share/wslu/conf. You can override the default configuration in \'/etc/wslu/conf\', \'/etc/wslu/custom.conf\', \'$HOME/.config/wslu/conf\', or \'$HOME/.wslurc\'. They will be read in the direction they are listed. +The default configuration is stored in /usr/share/wslu/conf. You can override the default configuration in \'/etc/wslu/conf\', \'/etc/wslu/custom.conf\', \'$HOME/.config/wslu/conf\', or \'$HOME/.wslurc\'. They will be read in the direction they are listed. .SH EXIT STATUS .TP .B 1 From b89be255279a76cd587b4c8123a9ac1fe4dfe2bc Mon Sep 17 00:00:00 2001 From: "Jinming Wu, Patrick" Date: Sun, 12 Nov 2023 18:35:57 +0800 Subject: [PATCH 10/22] ci: upgrade CI pengwin deployment ruby version --- .github/workflows/pkgbuild.yml | 2 +- .github/workflows/pkgdeploy.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pkgbuild.yml b/.github/workflows/pkgbuild.yml index f3430770..d21b80eb 100644 --- a/.github/workflows/pkgbuild.yml +++ b/.github/workflows/pkgbuild.yml @@ -52,7 +52,7 @@ jobs: name: Pengwin Deploying needs: pgwbuild runs-on: ubuntu-20.04 - container: circleci/ruby:2.3-jessie + container: cimg/ruby:2.7 steps: - name: Retrive package for deployment uses: actions/download-artifact@v1 diff --git a/.github/workflows/pkgdeploy.yaml b/.github/workflows/pkgdeploy.yaml index 8fa4defb..ddc2af41 100644 --- a/.github/workflows/pkgdeploy.yaml +++ b/.github/workflows/pkgdeploy.yaml @@ -47,7 +47,7 @@ jobs: name: Pengwin Deploying needs: pgwbuild runs-on: ubuntu-20.04 - container: circleci/ruby:2.3-jessie + container: cimg/ruby:2.7 steps: - name: Retrive package for deployment uses: actions/download-artifact@v1 From 1e450d8a75cafc40dffe0d9d326dc54523bba161 Mon Sep 17 00:00:00 2001 From: "Jinming Wu, Patrick" Date: Sun, 12 Nov 2023 18:52:16 +0800 Subject: [PATCH 11/22] fix: [#290] use proper folder for the states --- src/wslu-header | 30 ++++++++++++++++++------------ src/wslusc.sh | 2 +- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/wslu-header b/src/wslu-header index e4e695ea..21d28007 100644 --- a/src/wslu-header +++ b/src/wslu-header @@ -30,6 +30,12 @@ wslu_prefix="PREFIXPLACEHOLDER" LC_ALL=C LANG=C +# current state location +wslu_state_dir=${XDG_STATE_HOME:-$HOME/.local/state}/wslu +if [ ! -d "$wslu_state_dir" ]; then + mkdir -p "$wslu_state_dir" +fi + # prevent bash -x set +x @@ -262,7 +268,7 @@ function chcp_com { function winps_exec { debug_echo "winps_exec: called with command $*" wslutmpbuild="$(wslu_get_build)" - cp="$(cat ~/.config/wslu/oemcp)" + cp="$(cat "${wslu_state_dir}"/oemcp)" [ "$wslutmpbuild" -ge $BN_OCT_NINETEEN ] || chcp_com "$cp" "$(interop_prefix)$(sysdrive_prefix)"/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; [Console]::InputEncoding = [System.Text.Encoding]::GetEncoding($cp); $*" EXIT_STATUS=$? @@ -294,32 +300,32 @@ function baseexec_gen { debug_echo "baseexec_gen: base_exe_folder_path: $wslu_base_exec_folder_path" if find "$wslu_base_exec_folder_path" -name "*.exe" -print -quit &>/dev/null; then debug_echo "baseexec_gen: found exe in wslu_base_exec_folder_path" - wslpath -w "$(find "$wslu_base_exec_folder_path" -name "*.exe" -print -quit)" > ~/.config/wslu/baseexec + wslpath -w "$(find "$wslu_base_exec_folder_path" -name "*.exe" -print -quit)" > "${wslu_state_dir}"/baseexec else debug_echo "baseexec_gen: do not have base exec in the folder; use fallback" - echo "$(wslpath -w "$(interop_prefix)$(sysdrive_prefix)")\\Windows\\System32\\wsl.exe" > ~/.config/wslu/baseexec + echo "$(wslpath -w "$(interop_prefix)$(sysdrive_prefix)")\\Windows\\System32\\wsl.exe" > "${wslu_state_dir}"/baseexec fi else debug_echo "baseexec_gen: imported distro" # if it is imported distro - echo "$(wslpath -w "$(interop_prefix)$(sysdrive_prefix)")Windows\\System32\\wsl.exe" > ~/.config/wslu/baseexec + echo "$(wslpath -w "$(interop_prefix)$(sysdrive_prefix)")Windows\\System32\\wsl.exe" > "${wslu_state_dir}"/baseexec fi else debug_echo "baseexec_gen: fallback mode" # older version fallback. - echo "$(wslpath -w "$(interop_prefix)$(sysdrive_prefix)")\\Windows\\System32\\wsl.exe" > ~/.config/wslu/baseexec + echo "$(wslpath -w "$(interop_prefix)$(sysdrive_prefix)")\\Windows\\System32\\wsl.exe" > "${wslu_state_dir}"/baseexec fi } function var_gen { debug_echo "var_gen: called" - date +"%s" > ~/.config/wslu/triggered_time + date +"%s" > "${wslu_state_dir}"/triggered_time - rm -f ~/.config/wslu/baseexec - rm -f ~/.config/wslu/oemcp + rm -f "${wslu_state_dir}"/baseexec + rm -f "${wslu_state_dir}"/oemcp # generate oem codepage - "$(interop_prefix)$(sysdrive_prefix)"/Windows/System32/reg.exe query "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Nls\\CodePage" /v OEMCP 2>&1 | sed -n 3p | sed -e 's|\r||g' | grep -o '[[:digit:]]*' > ~/.config/wslu/oemcp + "$(interop_prefix)$(sysdrive_prefix)"/Windows/System32/reg.exe query "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Nls\\CodePage" /v OEMCP 2>&1 | sed -n 3p | sed -e 's|\r||g' | grep -o '[[:digit:]]*' > "${wslu_state_dir}"/oemcp # generate base exe location baseexec_gen @@ -393,15 +399,15 @@ fi # This gets tirggered then: # 1. if it's the first time the script is triggered, i.e., -# ~/.config/wslu/triggered time +# ${wslu_state_dir}/triggered time # 2. if update_time is also not present, i.e., # badly installed packages or installed via install script -if [ ! -f ~/.config/wslu/triggered_time ] || [ ! -f /usr/share/wslu/updated_time ]; then +if [ ! -f "${wslu_state_dir}"/triggered_time ] || [ ! -f /usr/share/wslu/updated_time ]; then debug_echo "first run or update_time not present; calling var_gen" var_gen # This gets triggered when: # installed time is larger than the last triggered time -elif [ "$(cat ~/.config/wslu/triggered_time)" -lt "$(cat /usr/share/wslu/updated_time)" ]; then +elif [ "$(cat "${wslu_state_dir}"/triggered_time)" -lt "$(cat /usr/share/wslu/updated_time)" ]; then debug_echo "upgraded package; calling var_gen" var_gen fi diff --git a/src/wslusc.sh b/src/wslusc.sh index 754bc0bc..9b4556ba 100644 --- a/src/wslusc.sh +++ b/src/wslusc.sh @@ -67,7 +67,7 @@ if [[ "$cname_header" != "" ]]; then dpath=$(wslpath "$(wslvar -l Desktop)") # Windows Desktop, WSL Sty. script_location="$(wslpath "$up_path")/wslu" # Windows wslu, Linux WSL Sty. script_location_win="$(double_dash_p "$up_path")\\wslu" # Windows wslu, Win Double Sty. - distro_location_win="$(double_dash_p "$(cat ~/.config/wslu/baseexec)")" # Distro Location, Win Double Sty. + distro_location_win="$(double_dash_p "$(cat "${wslu_state_dir}"/baseexec)")" # Distro Location, Win Double Sty. # change param according to the exec. distro_param="run" From 86cc1e5d3ec8920ae9dcc65cb9b1f64fe074a85d Mon Sep 17 00:00:00 2001 From: "Jinming Wu, Patrick" Date: Sun, 12 Nov 2023 23:53:30 +0800 Subject: [PATCH 12/22] chore: [#288] improve documentation a bit --- CONTRIBUTING.md | 6 ++++++ README.md | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index caa237ad..503d70ea 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,6 +2,12 @@ We love pull requests from everyone. By participating in this project, you agree to abide by [Code of Conduct](CODE_OF_CONDUCT.md). +> **ATTENTION!** +> +> Built-in versions of wslu in Ubuntu are no longer supported by me. +> +> If you have problems, please check whther you are using the [PPA version of wslu](https://launchpad.net/~wslutilities/+archive/ubuntu/wslu). If not, please report to the Ubuntu WSL team; However, the PPA version of wslu will address most issue that come from the built-in version. + ## Code contributions ### Setup diff --git a/README.md b/README.md index 5f390e00..016a90c3 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,16 @@ [![GitHub license](https://img.shields.io/github/license/wslutilities/wslu?style=flat-square&label=license&color=blue&logo=github)](https://github.com/wslutilities/wslu/blob/master/LICENSE) [![GitHub (pre-)release](https://img.shields.io/github/v/release/wslutilities/wslu?include_prereleases&logo=github&style=flat-square)](https://github.com/wslutilities/wslu) -[![Twitter Follow](https://img.shields.io/twitter/follow/wslutilities?style=flat-square&logo=twitter&color=1DA1F2&label=follow)](https://twitter.com/wslutilities) [![Mastodon Follow](https://img.shields.io/mastodon/follow/108802672885079993?color=6364FF&domain=https%3A%2F%2Ffosstodon.org&label=follow&logo=mastodon&logoColor=6364FF&style=flat-square)](https://fosstodon.org/@wslutilities) +> **ATTENTION!** +> +> Built-in versions of wslu in Ubuntu are no longer supported by me. +> +> If you have problems, please check whther you are using the [PPA version of wslu](https://launchpad.net/~wslutilities/+archive/ubuntu/wslu). If not, please report to the Ubuntu WSL team; However, the PPA version of wslu will address most issue that come from the built-in version. + This is a collection of utilities for the Linux Subsystem for Windows (WSL), such as converting Linux paths to Windows paths or creating Linux application shortcuts on the Windows Desktop. - Requires at least Windows 10 Creators Update; From c818f000c3ab5b102f5508f7fa54000f48dd934e Mon Sep 17 00:00:00 2001 From: "Jinming Wu, Patrick" Date: Mon, 13 Nov 2023 00:34:12 +0800 Subject: [PATCH 13/22] fix: [#268] allow skipping validation --- docs/wslview.1 | 8 +++++++- src/etc/conf | 5 ++++- src/etc/user/conf | 5 ++++- src/wslview.sh | 11 +++++++++-- tests/wslview.bats | 4 ++-- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/docs/wslview.1 b/docs/wslview.1 index 6cd27bf4..e3802fbe 100644 --- a/docs/wslview.1 +++ b/docs/wslview.1 @@ -5,7 +5,7 @@ - Component of WSL Utilities .SH SYNOPSIS .B wslview, wview, wslstart, wstart -.RB [ \-hvur ] +.RB [ \-hsvur ] .PP .B wslview, wview, wslstart, wstart .I LINK/FILE @@ -19,6 +19,9 @@ print a simple help. .B -v, --version print current version. .TP +.B -s, --skip-validation-check +skip url validation check. +.TP .B -u, --unreg-as-browser remove \fBwslview\fR as the default WSL web browser. .TP @@ -35,6 +38,9 @@ cmd: use cmd.exe to start website/folder/file cmd_explorer: use explorer.exe via cmd.exe to start website/folder/file .in .fi +.TP +.B WSLVIEW_SKIP_VALIDATION_CHECK +whether to skip validation check. Default is 1, which is not skipping. Can be either `0` or `1`. .SH AUTHOR Created by Patrick Wu .SH REPORTING BUGS diff --git a/src/etc/conf b/src/etc/conf index e41ac504..dbc82423 100644 --- a/src/etc/conf +++ b/src/etc/conf @@ -66,4 +66,7 @@ WSLVAR_DEFAULT_VARTYPE=1 # powershell: use powershell.exe to start website/folder/file # cmd: use cmd.exe to start website/folder/file # cmd_explorer: use explorer.exe via cmd.exe to start website/folder/file -WSLVIEW_DEFAULT_ENGINE="powershell" \ No newline at end of file +WSLVIEW_DEFAULT_ENGINE="powershell" + +# wslview: whether to skip validation check. Default is 1, which is not skipping. Can be either `0` or `1`. +WSLVIEW_SKIP_VALIDATION_CHECK=1 \ No newline at end of file diff --git a/src/etc/user/conf b/src/etc/user/conf index 3879d437..6a7a69e8 100644 --- a/src/etc/user/conf +++ b/src/etc/user/conf @@ -58,4 +58,7 @@ # powershell: use powershell.exe to start website/folder/file # cmd: use cmd.exe to start website/folder/file # cmd_explorer: use explorer.exe via cmd.exe to start website/folder/file -# WSLVIEW_DEFAULT_ENGINE="powershell" \ No newline at end of file +# WSLVIEW_DEFAULT_ENGINE="powershell" + +# wslview: whether to skip validation check. Default is 1, which is not skipping. Can be either `0` or `1`. +# WSLVIEW_SKIP_VALIDATION_CHECK=1 \ No newline at end of file diff --git a/src/wslview.sh b/src/wslview.sh index 1c26d494..1562ebae 100644 --- a/src/wslview.sh +++ b/src/wslview.sh @@ -1,7 +1,8 @@ # shellcheck shell=bash lname="" +skip_validation_check=${WSLVIEW_SKIP_VALIDATION_CHECK:-1} -help_short="$0 [-hvur]\n$0 [-E ENGINE] LINK/FILE" +help_short="$0 [-hsvur]\n$0 [-E ENGINE] LINK/FILE" function del_reg_alt { if [ "$distro" == "archlinux" ] || [ "$distro" == "alpine" ]; then @@ -36,6 +37,7 @@ function url_validator { while [ "$1" != "" ]; do case "$1" in + -s|--skip-validation-check) skip_validation_check=0; shift;; -r|--reg-as-browser) add_reg_alt;; -u|--unreg-as-browser) del_reg_alt;; -h|--help) help "$0" "$help_short"; exit;; @@ -68,7 +70,12 @@ if [[ "$lname" != "" ]]; then fi debug_echo "properfile_full_path: $properfile_full_path" debug_echo "validating whether if it is a link" - if (url_validator "$lname") && [ -z "$properfile_full_path" ]; then + is_valid_url=$(url_validator "$lname") + if [ "$skip_validation_check" -eq 0 ]; then + debug_echo "Skipping validation check" + is_valid_url=0 + fi + if [[ "$is_valid_url" -eq 0 ]] && [ -z "$properfile_full_path" ]; then debug_echo "It is a link" cmd="\"$lname\"" elif [[ "$lname" =~ ^file:\/\/(\/)+[A-Za-z]\:.*$ ]] || [[ "$lname" =~ ^[A-Za-z]\:.*$ ]]; then diff --git a/tests/wslview.bats b/tests/wslview.bats index f6a22285..eb4882ce 100644 --- a/tests/wslview.bats +++ b/tests/wslview.bats @@ -15,14 +15,14 @@ setup() { @test "wslview - Help" { run out/wslview --help [ "${lines[0]}" = "wslview - Part of wslu, a collection of utilities for Linux Subsystem for Windows (WSL)" ] - [[ "${lines[1]}" =~ ^Usage\:\ .*wslview\ \[\-hvur\]$ ]] + [[ "${lines[1]}" =~ ^Usage\:\ .*wslview\ \[\-hsvur\]$ ]] [[ "${lines[2]}" =~ ^.*wslview\ \[\-E\ ENGINE\]\ LINK/FILE$ ]] } @test "wslview - Help - Alt." { run out/wslview -h [ "${lines[0]}" = "wslview - Part of wslu, a collection of utilities for Linux Subsystem for Windows (WSL)" ] - [[ "${lines[1]}" =~ ^Usage\:\ .*wslview\ \[\-hvur\]$ ]] + [[ "${lines[1]}" =~ ^Usage\:\ .*wslview\ \[\-hsvur\]$ ]] [[ "${lines[2]}" =~ ^.*wslview\ \[\-E\ ENGINE\]\ LINK/FILE$ ]] } From b6fa4b70b22909337cb13b5b2ea9845f733f60ff Mon Sep 17 00:00:00 2001 From: "Jinming Wu, Patrick" Date: Mon, 13 Nov 2023 01:15:45 +0800 Subject: [PATCH 14/22] fix: [#264] make DESTDIR properly configured in header --- CONTRIBUTING.md | 1 + Makefile | 2 +- src/wslu-header | 17 +++++++++-------- src/wslvar.sh | 8 ++++---- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 503d70ea..f12215c3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -89,6 +89,7 @@ For contributing, there are several functions and variables built-in the header - `wslu_util_name` - current utility name - `wslu_version` - wslu version, written by `VERSION` - `wslu_prefix` - the location `wslu` installed to, written by the `PREFIX` during the make. + - `wslu_dest_dir` - the location `wslu` installed to, written by the `DESTDIR` during the make. - `wslu_debug` - the variable used for calling utility across. This will allow calling the `--debug` option for other `wslu` utilities inside script easier. - Formatting: `black`, `red`, `green`, `brown`, `blue`, `purple`, `cyan`, `yellow`, `white`, `dark_gray`, `light_red`, `light_green`, `light_blue`, `light_purple`, `light_cyan`, `light_gray`, `orange`, `light_orange`, `deep_purple`, `bold`, `reset` - Indicator: `info`, `input_info`, `error`, `warn` diff --git a/Makefile b/Makefile index d4ebbfbe..23990093 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ VERTMP = $(shell cat ./VERSION) all: doc [ -d $(OUTPATH) ] || mkdir $(OUTPATH) - sed -e 's/VERSIONPLACEHOLDER/'$(VERTMP)'/' -e 's|PREFIXPLACEHOLDER|'$(PREFIX)'|' $(HEADER) > $(HEADER).tmp; \ + sed -e 's/VERSIONPLACEHOLDER/'$(VERTMP)'/' -e 's|PREFIXPLACEHOLDER|'$(PREFIX)'|' -e 's|DESTDIRPLACEHOLDER|'$(DESTDIR)'|' $(HEADER) > $(HEADER).tmp; \ for file in $(SOURCES); do \ cat $(HEADER).tmp $$file > $(OUTPATH)/`basename $$file`; \ mv $(OUTPATH)/`basename $$file` $(OUTPATH)/`basename $$file .sh`; \ diff --git a/src/wslu-header b/src/wslu-header index 21d28007..85a016bc 100644 --- a/src/wslu-header +++ b/src/wslu-header @@ -25,6 +25,7 @@ wslu_util_name=$(basename "$wslu_util_fullpath") # Version wslu_version=VERSIONPLACEHOLDER wslu_prefix="PREFIXPLACEHOLDER" +wslu_dest_dir="DESTDIRPLACEHOLDER" # Speed up script by using unicode. LC_ALL=C @@ -150,20 +151,20 @@ function error_echo { } # source default config -if [ -f "${wslu_prefix}/share/wslu/conf" ]; then +if [ -f "${wslu_dest_dir}${wslu_prefix}/share/wslu/conf" ]; then debug_echo "source default setting" - source "${wslu_prefix}/share/wslu/conf" + source "${wslu_dest_dir}${wslu_prefix}/share/wslu/conf" fi # source user-defined config -if [ -f "${wslu_prefix}/share/wslu/custom.conf" ]; then - debug_echo "${wslu_prefix}/share/wslu/custom.conf found, sourcing" - source "${wslu_prefix}/share/wslu/custom.conf" +if [ -f "${wslu_dest_dir}${wslu_prefix}/share/wslu/custom.conf" ]; then + debug_echo "${wslu_dest_dir}${wslu_prefix}/share/wslu/custom.conf found, sourcing" + source "${wslu_dest_dir}${wslu_prefix}/share/wslu/custom.conf" fi -if [ -f "/etc/wslu/conf" ]; then - debug_echo "/etc/wslu/conf found, sourcing" - source "/etc/wslu/conf" +if [ -f "${wslu_dest_dir}/etc/wslu/conf" ]; then + debug_echo "${wslu_dest_dir}/etc/wslu/conf found, sourcing" + source "${wslu_dest_dir}/etc/wslu/conf" fi if [ -f "/etc/wslu/custom.conf" ]; then diff --git a/src/wslvar.sh b/src/wslvar.sh index 1ae9164e..a770d09c 100644 --- a/src/wslvar.sh +++ b/src/wslvar.sh @@ -1,5 +1,5 @@ # shellcheck shell=bash -var_type=1 +var_type=${WSLVAR_DEFAULT_VARTYPE:-1} help_short="wslvar [-sl] NAME\nwslvar [-hvSL]" @@ -25,7 +25,7 @@ function cl_destoryer { function caller { if [ "$*" != "" ]; then - case $WSLVAR_DEFAULT_VARTYPE in + case $var_type in 1) p="$(cl_destoryer "$(call_sys "$@")")";; 2) p="$(cl_destoryer "$(call_shell "$@")")";; *) error_echo "Invalid variable type. Aborted." 22;; @@ -38,8 +38,8 @@ function caller { while [ "$1" != "" ]; do case "$1" in - -s|--sys) WSLVAR_DEFAULT_VARTYPE=1; shift;; - -l|--shell) WSLVAR_DEFAULT_VARTYPE=2; shift;; + -s|--sys) var_type=1; shift;; + -l|--shell) var_type=2; shift;; -S|--getsys) view_sys; exit;; -L|--getshell) view_shell; exit;; -h|--help) help "$0" "$help_short"; exit;; From 7c6a9ed3df608340f216dfe257382062b36320f9 Mon Sep 17 00:00:00 2001 From: "Jinming Wu, Patrick" Date: Sat, 30 Dec 2023 00:09:51 +0800 Subject: [PATCH 15/22] fix: [#295] decode file protocol url properly --- src/wslview.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/wslview.sh b/src/wslview.sh index 1562ebae..efa4bab3 100644 --- a/src/wslview.sh +++ b/src/wslview.sh @@ -4,6 +4,8 @@ skip_validation_check=${WSLVIEW_SKIP_VALIDATION_CHECK:-1} help_short="$0 [-hsvur]\n$0 [-E ENGINE] LINK/FILE" +function fileprotocoldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; } + function del_reg_alt { if [ "$distro" == "archlinux" ] || [ "$distro" == "alpine" ]; then error_echo "Unsupported action for this distro. Aborted." 34 @@ -55,6 +57,8 @@ if [[ "$lname" != "" ]]; then # file:/// protocol used in linux if [[ "$lname" =~ ^file:\/\/.*$ ]] && [[ ! "$lname" =~ ^file:\/\/(\/)+[A-Za-z]\:.*$ ]]; then debug_echo "Received file:/// protocol used in linux" + # convert before set + lname="$(fileprotocoldecode "$lname")" [ "$wslutmpbuild" -ge "$BN_MAY_NINETEEN" ] || error_echo "This protocol is not supported before version 1903." 34 properfile_full_path="$(readlink -f "${lname//file:\/\//}")" # Linux absolute path From ea34a92840d8a20635ec0ed19b2b751067b6cd06 Mon Sep 17 00:00:00 2001 From: "Jinming Wu, Patrick" Date: Sat, 30 Dec 2023 23:27:59 +0800 Subject: [PATCH 16/22] feat: [#293] allow set path with param -e to set BROWSER variable --- docs/wslview.1 | 5 ++++- src/wslview.sh | 27 ++++++++++++++++++++++++++- tests/wslview.bats | 4 ++-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/docs/wslview.1 b/docs/wslview.1 index e3802fbe..7d682bc5 100644 --- a/docs/wslview.1 +++ b/docs/wslview.1 @@ -5,7 +5,7 @@ - Component of WSL Utilities .SH SYNOPSIS .B wslview, wview, wslstart, wstart -.RB [ \-hsvur ] +.RB [ \-ehsvurE ] .PP .B wslview, wview, wslstart, wstart .I LINK/FILE @@ -27,6 +27,9 @@ remove \fBwslview\fR as the default WSL web browser. .TP .B -r, --reg-as-browser register \fBwslview\fR as the default WSL web browser. +.TP +.B -e, --export-as-browser +register \fBwslview\fR as the default WSL web browser using export method. .SH CONFIGURATION .TP .B WSLVIEW_DEFAULT_ENGINE diff --git a/src/wslview.sh b/src/wslview.sh index efa4bab3..a8c34d12 100644 --- a/src/wslview.sh +++ b/src/wslview.sh @@ -2,7 +2,7 @@ lname="" skip_validation_check=${WSLVIEW_SKIP_VALIDATION_CHECK:-1} -help_short="$0 [-hsvur]\n$0 [-E ENGINE] LINK/FILE" +help_short="$0 [-ehsvurE]\n$0 [-E ENGINE] LINK/FILE" function fileprotocoldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; } @@ -27,6 +27,30 @@ function add_reg_alt { fi } +function add_browser_export { + # find all possible shell rc file and append export BROWSER="/usr/bin/wslview" at the end; if found existing export, comment it out + # Define the shell rc files to search + rc_files=(".bashrc" ".zshrc" ".kshrc" ".cshrc" ".tcshrc") + + # Loop over each file + for rc_file in "${rc_files[@]}"; do + # Check if the file exists + if [ -f "$HOME/$rc_file" ]; then + echo "Processing $rc_file..." + + # Comment out existing BROWSER export + if grep -q "export BROWSER=" "$HOME/$rc_file"; then + echo "Commenting out existing BROWSER export in $rc_file..." + $SED -i 's/^export BROWSER=/#export BROWSER=/' "$HOME/$rc_file" + fi + + # Append new BROWSER export + echo "Appending new BROWSER export to $rc_file..." + echo 'export BROWSER="/usr/bin/wslview"' >> "$HOME/$rc_file" + fi + done +} + function url_validator { content=$(curl --head --silent -g "$*" | head -n 1) if [ -n "$content" ]; then @@ -42,6 +66,7 @@ while [ "$1" != "" ]; do -s|--skip-validation-check) skip_validation_check=0; shift;; -r|--reg-as-browser) add_reg_alt;; -u|--unreg-as-browser) del_reg_alt;; + -e|--export-as-browser) add_browser_export;; -h|--help) help "$0" "$help_short"; exit;; -v|--version) version; exit;; -E|--engine) shift; WSLVIEW_DEFAULT_ENGINE="$1"; shift;; diff --git a/tests/wslview.bats b/tests/wslview.bats index eb4882ce..cad22dff 100644 --- a/tests/wslview.bats +++ b/tests/wslview.bats @@ -15,14 +15,14 @@ setup() { @test "wslview - Help" { run out/wslview --help [ "${lines[0]}" = "wslview - Part of wslu, a collection of utilities for Linux Subsystem for Windows (WSL)" ] - [[ "${lines[1]}" =~ ^Usage\:\ .*wslview\ \[\-hsvur\]$ ]] + [[ "${lines[1]}" =~ ^Usage\:\ .*wslview\ \[\-ehsvurE\]$ ]] [[ "${lines[2]}" =~ ^.*wslview\ \[\-E\ ENGINE\]\ LINK/FILE$ ]] } @test "wslview - Help - Alt." { run out/wslview -h [ "${lines[0]}" = "wslview - Part of wslu, a collection of utilities for Linux Subsystem for Windows (WSL)" ] - [[ "${lines[1]}" =~ ^Usage\:\ .*wslview\ \[\-hsvur\]$ ]] + [[ "${lines[1]}" =~ ^Usage\:\ .*wslview\ \[\-ehsvurE\]$ ]] [[ "${lines[2]}" =~ ^.*wslview\ \[\-E\ ENGINE\]\ LINK/FILE$ ]] } From e52ebcfb91645d931ca924820d3611749cdc161b Mon Sep 17 00:00:00 2001 From: "Jinming Wu, Patrick" Date: Sun, 31 Dec 2023 00:23:46 +0800 Subject: [PATCH 17/22] fix: [#294] add bash version requirement. --- src/wslu-header | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/wslu-header b/src/wslu-header index 85a016bc..a76eaa60 100644 --- a/src/wslu-header +++ b/src/wslu-header @@ -40,6 +40,8 @@ fi # prevent bash -x set +x +bash_version_major=$(echo $BASH_VERSION | cut -d'.' -f1) + # pipeline content to pipe... if it is wslclip if [[ "$wslu_util_name" == "wslclip" ]]; then if [[ -p /dev/stdin ]]; then @@ -150,6 +152,11 @@ function error_echo { exit "$2" } +# Check if the major version number is greater than 5 +if [ $(expr $bash_version_major \> 5) -ne 1 ]; then + error_echo "You should use Bash 5 and higher; exiting." 1 +fi + # source default config if [ -f "${wslu_dest_dir}${wslu_prefix}/share/wslu/conf" ]; then debug_echo "source default setting" From b08c0b813e341b7966697b013990ae0d9fcfebf7 Mon Sep 17 00:00:00 2001 From: "Jinming Wu, Patrick" Date: Sun, 31 Dec 2023 12:48:49 +0800 Subject: [PATCH 18/22] fix: [#291] allow disable reading from registry --- docs/wslu.7 | 4 ++++ src/etc/conf | 4 ++++ src/etc/user/conf | 4 ++++ src/wslu-header | 20 +++++++++++++------- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/docs/wslu.7 b/docs/wslu.7 index 464fa381..546aec55 100644 --- a/docs/wslu.7 +++ b/docs/wslu.7 @@ -80,6 +80,10 @@ unsupported feature (for your Windows 10 build) .TP .B 40 Unknown system input. +.SH CONFIGURATION +.TP +.B WSLVIEW_DEFAULT_ENGINE +control whether to enable the chcp workaround for powershell. By default it is true; if you encounter any PowerShell issues, you can try to disable it. .SH BUG Report bugs to ; For Ubuntu specific bugs, report to . diff --git a/src/etc/conf b/src/etc/conf index dbc82423..539b8fe2 100644 --- a/src/etc/conf +++ b/src/etc/conf @@ -19,6 +19,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# wslu: control whether to enable the chcp workaround for powershell. +# By default it is true; if you encounter any PowerShell issues, you can try to disable it. +WSLU_POWERSHELL_CHCP_WORKAROUND=true + # wslfetch: the sections of info from wslsys to show in wslfetch. # Available options: # windows-install-date diff --git a/src/etc/user/conf b/src/etc/user/conf index 6a7a69e8..39c71dc5 100644 --- a/src/etc/user/conf +++ b/src/etc/user/conf @@ -11,6 +11,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# wslu: control whether to enable the chcp workaround for powershell. +# By default it is true; if you encounter any PowerShell issues, you can try to disable it. +# WSLU_POWERSHELL_CHCP_WORKAROUND=true + # wslfetch: the sections of info from wslsys to show in wslfetch. # Available options: # windows-install-date diff --git a/src/wslu-header b/src/wslu-header index a76eaa60..205b5bd5 100644 --- a/src/wslu-header +++ b/src/wslu-header @@ -275,13 +275,19 @@ function chcp_com { function winps_exec { debug_echo "winps_exec: called with command $*" - wslutmpbuild="$(wslu_get_build)" - cp="$(cat "${wslu_state_dir}"/oemcp)" - [ "$wslutmpbuild" -ge $BN_OCT_NINETEEN ] || chcp_com "$cp" - "$(interop_prefix)$(sysdrive_prefix)"/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; [Console]::InputEncoding = [System.Text.Encoding]::GetEncoding($cp); $*" - EXIT_STATUS=$? - [ "$wslutmpbuild" -ge $BN_OCT_NINETEEN ] || chcp_com 65001 - return $EXIT_STATUS + if [[ "$WSLU_POWERSHELL_CHCP_WORKAROUND" == "true" ]]; then + wslutmpbuild="$(wslu_get_build)" + cp="$(cat "${wslu_state_dir}"/oemcp)" + [ "$wslutmpbuild" -ge $BN_OCT_NINETEEN ] || chcp_com "$cp" + "$(interop_prefix)$(sysdrive_prefix)"/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; [Console]::InputEncoding = [System.Text.Encoding]::GetEncoding($cp); $*" + EXIT_STATUS=$? + [ "$wslutmpbuild" -ge $BN_OCT_NINETEEN ] || chcp_com 65001 + return $EXIT_STATUS + else + "$(interop_prefix)$(sysdrive_prefix)"/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "$*" + EXIT_STATUS=$? + return $EXIT_STATUS + fi } function cmd_exec { From d3e688ff1ec32f7b9602ca35349c77b50a66d0c7 Mon Sep 17 00:00:00 2001 From: "Jinming Wu, Patrick" Date: Sun, 31 Dec 2023 23:00:27 +0800 Subject: [PATCH 19/22] chore: shellcheck fix --- src/wslu-header | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wslu-header b/src/wslu-header index 205b5bd5..9645f333 100644 --- a/src/wslu-header +++ b/src/wslu-header @@ -40,7 +40,7 @@ fi # prevent bash -x set +x -bash_version_major=$(echo $BASH_VERSION | cut -d'.' -f1) +bash_version_major=$(echo "$BASH_VERSION" | cut -d'.' -f1) # pipeline content to pipe... if it is wslclip if [[ "$wslu_util_name" == "wslclip" ]]; then @@ -153,7 +153,7 @@ function error_echo { } # Check if the major version number is greater than 5 -if [ $(expr $bash_version_major \> 5) -ne 1 ]; then +if [ "$(expr "$bash_version_major" \>= 5)" -ne 1 ]; then error_echo "You should use Bash 5 and higher; exiting." 1 fi From 4dc00179dbcdffe880c7561835f09b9106ef3075 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Fri, 5 Jan 2024 16:40:12 -0800 Subject: [PATCH 20/22] perf: Use POSIX Parameter substitution instead of `basename` exec --- extras/scripts/manpage_deploy.bash | 2 +- src/wslfetch.sh | 2 +- src/wslgsu.sh | 3 ++- src/wslu-header | 5 +++-- src/wslusc.sh | 8 ++++---- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/extras/scripts/manpage_deploy.bash b/extras/scripts/manpage_deploy.bash index 069ebb70..479fa66e 100644 --- a/extras/scripts/manpage_deploy.bash +++ b/extras/scripts/manpage_deploy.bash @@ -5,7 +5,7 @@ if [ ! -d "./website/wslu/man/${wslu_ver}" ] ; then cp ./docs/*.html ./website/wslu/man/${wslu_ver} rm -f ./website/wslu/man/*.html for f in $(ls -d ./website/wslu/man/${wslu_ver}/*.html); do - fname="$(basename ${f})" + fname="${f##*/}" ln -s ./${wslu_ver}/${fname} ./website/wslu/man/${fname} done fi diff --git a/src/wslfetch.sh b/src/wslfetch.sh index 150ac6aa..7e8e6c17 100644 --- a/src/wslfetch.sh +++ b/src/wslfetch.sh @@ -4,7 +4,7 @@ is_generic=0 help_short="wslfetch [-hvcg] [-t THEME] [-o OPTIONS]" -PARSED_ARGUMENTS=$(getopt -a -n "$(basename "$wslu_util_name")" -o hvtcgo: --long help,version,theme,colorbar,generic,options: -- "$@") +PARSED_ARGUMENTS=$(getopt -a -n "${wslu_util_name##*/}" -o hvtcgo: --long help,version,theme,colorbar,generic,options: -- "$@") #shellcheck disable=SC2181 [ "$?" != "0" ] && help "$wslu_util_name" "$help_short" diff --git a/src/wslgsu.sh b/src/wslgsu.sh index 9afdd128..3d8a5500 100644 --- a/src/wslgsu.sh +++ b/src/wslgsu.sh @@ -73,7 +73,8 @@ if [[ "$wa_gs_commd" != "" ]] || [[ $isWakeup -eq 1 ]]; then # handling no name given case if [[ "$wa_gs_name" = "" ]]; then debug_echo "No name given, automatically generate" - wa_gs_name=$(basename "$(echo "$wa_gs_commd" | awk '{print $1}')") + wa_gs_name=$(echo "$wa_gs_commd" | awk '{print $1}') + wa_gs_name=${wa_gs_name##*/} fi wa_gs_commd="wsl.exe -d $WSL_DISTRO_NAME -u $wa_gs_user $wa_gs_commd" wa_gs_dscp="Executing following command \`$wa_gs_name\` from $WSL_DISTRO_NAME when computer start up; Generated By WSL Utilities" diff --git a/src/wslu-header b/src/wslu-header index 9645f333..27ec8e18 100644 --- a/src/wslu-header +++ b/src/wslu-header @@ -20,7 +20,7 @@ # Current utility wslu_util_fullpath="$0" -wslu_util_name=$(basename "$wslu_util_fullpath") +wslu_util_name="${wslu_util_fullpath##*/}" # Version wslu_version=VERSIONPLACEHOLDER @@ -226,7 +226,8 @@ function sysdrive_prefix { if [ "$(echo "$pt" | wc -l)" -eq 1 ]; then if [ -d "$pt/Windows/System32" ]; then hard_reset=1 - win_location="$(basename "$pt")" + pt=${pt%/} + win_location="${pt##*/}" break fi fi diff --git a/src/wslusc.sh b/src/wslusc.sh index 9b4556ba..db42493a 100644 --- a/src/wslusc.sh +++ b/src/wslusc.sh @@ -9,7 +9,7 @@ base_converter_engine=${WSLUSC_BASE_CONVERTER_ENGINE:-"imagemagick"} help_short="wslusc [-IsgN] [-d SHORTCUT_FILE] [-e PATH] [-n NAME] [-i FILE] COMMAND\nwslusc [-hv]" -PARSED_ARGUMENTS=$(getopt -a -n "$(basename "$wslu_util_name")" -o hvd:Ie:n:i:gNs --long help,version,shortcut-debug:,interactive,path:,name:,icon:,gui,native,smart-icon -- "$@") +PARSED_ARGUMENTS=$(getopt -a -n "${wslu_util_name##*/}" -o hvd:Ie:n:i:gNs --long help,version,shortcut-debug:,interactive,path:,name:,icon:,gui,native,smart-icon -- "$@") #shellcheck disable=SC2181 [ "$?" != "0" ] && help "$wslu_util_name" "$help_short" @@ -93,7 +93,7 @@ if [[ "$cname_header" != "" ]]; then [ -z "$cname_header" ] && error_echo "Bad or invalid input; Aborting" 30 # handling no name given case - new_cname=$(basename "$cname_header") + new_cname="${cname_header##*/}" # handling name given case if [[ "$customname" != "" ]]; then new_cname=$customname @@ -114,7 +114,7 @@ if [[ "$cname_header" != "" ]]; then #handling smart icon first; always first if [[ "$WSLUSC_SMART_ICON_DETECTION" == "true" ]]; then if wslpy_check; then - tmp_fcname="$(basename "$cname_header")" + tmp_fcname="${cname_header##*/}" iconpath="$(python3 -c "import wslpy.__internal__; print(wslpy.__internal__.find_icon(\"$tmp_fcname\"))")" echo "${info} Icon Detector found icon $tmp_fcname at: $iconpath" else @@ -123,7 +123,7 @@ if [[ "$cname_header" != "" ]]; then fi # normal detection section - icon_filename="$(basename "$iconpath")" + icon_filename="${iconpath##*/}" ext="${iconpath##*.}" if [[ ! -f $iconpath ]]; then From 060b047875c55b3bbc4cd1814caa8168cbab89e6 Mon Sep 17 00:00:00 2001 From: Jasper Zonneveld Date: Thu, 11 Jan 2024 15:15:46 +0100 Subject: [PATCH 21/22] fix: [#268] do not validate URL when skip flag is used --- src/wslview.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wslview.sh b/src/wslview.sh index a8c34d12..7098f9f4 100644 --- a/src/wslview.sh +++ b/src/wslview.sh @@ -98,11 +98,12 @@ if [[ "$lname" != "" ]]; then properfile_full_path="$(readlink -f "${lname}")" fi debug_echo "properfile_full_path: $properfile_full_path" - debug_echo "validating whether if it is a link" - is_valid_url=$(url_validator "$lname") if [ "$skip_validation_check" -eq 0 ]; then debug_echo "Skipping validation check" is_valid_url=0 + else + debug_echo "Validating whether if it is a link" + is_valid_url=$(url_validator "$lname") fi if [[ "$is_valid_url" -eq 0 ]] && [ -z "$properfile_full_path" ]; then debug_echo "It is a link" From 37da694b98b892d91e1a9eeacc62c20e1fa4d94d Mon Sep 17 00:00:00 2001 From: "Jinming Wu, Patrick" Date: Sun, 10 Mar 2024 21:52:01 +0800 Subject: [PATCH 22/22] chore: update VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 00cf9325..658e3ea6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.1.1-1 +4.1.2-1