From e84ce4f2d29e11059cdcc1a59e943462d41c8e9c Mon Sep 17 00:00:00 2001 From: Davide Depau Date: Fri, 6 Sep 2019 19:51:56 +0200 Subject: [PATCH] Fix WSL compatibility --- shcrt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/shcrt b/shcrt index e805ef9..fb3c31c 100644 --- a/shcrt +++ b/shcrt @@ -9,13 +9,21 @@ function is_wsl { return $? } +function wsl_win_var { + /mnt/c/Windows/System32/cmd.exe /C "echo $1" +} + function win_path_to_wsl { - echo "$1" | sed '[\]|/|g' + if [[ "$1" != "" ]]; then + echo "$1" | sed -e 's|\\|/|g' -e 's|\(.*\):|/mnt/\L\1|' + else + cat - | sed -e 's|\\|/|g' -e 's|\(.*\):|/mnt/\L\1|' + fi } function scrt_session_path { if is_wsl; then - appdata="$(cmd.exe /C 'echo %APPDATA%')" + appdata="$(wsl_win_var '%APPDATA%' | win_path_to_wsl)" echo "$appdata/VanDyke/Config/Sessions" else echo "$HOME/.vandyke/SecureCRT/Config/Sessions" @@ -26,10 +34,10 @@ session_path="$(scrt_session_path)" current_path="" function scrt_cd { - if [ ! -d "$session_path/$current_path" ]; then + if [ ! -d "$session_path/$current_path/$1" ]; then return 1 fi - current_path="$current_path/$1" + current_path="$(realpath -m --relative-to "$session_path" "$current_path/$1")" } function scrt_ls {