126 lines
2.7 KiB
Bash
Executable file
126 lines
2.7 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
export supermode="dialog"
|
|
|
|
export SHELL_LIBRARY_PATH="$SHELL_LIBRARY_PATH:./easybashgui/lib"
|
|
export PATH="$PATH:./easybashgui/src"
|
|
source easybashgui
|
|
|
|
function is_wsl {
|
|
grep -q Microsoft /proc/version
|
|
return $?
|
|
}
|
|
|
|
function wsl_win_var {
|
|
/mnt/c/Windows/System32/cmd.exe /C "echo $1"
|
|
}
|
|
|
|
function win_path_to_wsl {
|
|
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="$(wsl_win_var '%APPDATA%' | win_path_to_wsl)"
|
|
echo "$appdata/VanDyke/Config/Sessions"
|
|
else
|
|
echo "$HOME/.vandyke/SecureCRT/Config/Sessions"
|
|
fi
|
|
}
|
|
|
|
if is_wsl; then
|
|
dir_char="+"
|
|
file_char=" "
|
|
else
|
|
dir_char="📁"
|
|
file_char="🔗"
|
|
fi
|
|
|
|
session_path="$(scrt_session_path)"
|
|
current_path=""
|
|
|
|
function scrt_cd {
|
|
newdir="$session_path/$current_path/$1"
|
|
if [ ! -d "$newdir" ]; then
|
|
return 1
|
|
fi
|
|
current_path="$(realpath --no-symlinks --relative-to "$session_path" "$newdir")"
|
|
}
|
|
|
|
function scrt_pwd {
|
|
echo "$session_path/$current_path"
|
|
}
|
|
|
|
function find_dirs_or_symlinks {
|
|
while read -r name; do
|
|
[ -d "$name" ] && echo "$name";
|
|
done < <(find $@)
|
|
}
|
|
|
|
function find_files_or_symlinks {
|
|
while read -r name; do
|
|
[ -f "$name" ] && echo "$name";
|
|
done < <(find $@)
|
|
}
|
|
|
|
function scrt_ls {
|
|
cwd="$(pwd)"
|
|
cd "$(scrt_pwd)"
|
|
|
|
find_dirs_or_symlinks -maxdepth 1 -mindepth 1 | sort | sed "s|./||" | while read dir; do
|
|
echo "$dir_char $dir\\$dir"
|
|
done
|
|
|
|
find_files_or_symlinks -maxdepth 1 -mindepth 1 | grep '.ini$' | grep -v 'Default.ini' | grep -v '__FolderData__.ini' | sort | sed 's|./||' | while read file; do
|
|
proto="$(cat "$file" | grep 'S:"Protocol Name"' | cut -d '=' -f 2 | sed 's|\r||g')"
|
|
echo "$file_char $(echo "$file" | sed 's/.ini$//') ($proto)\\$file"
|
|
done
|
|
|
|
cd "$cwd"
|
|
}
|
|
|
|
function scrt_menu {
|
|
listing="$(scrt_ls)"
|
|
menu_listing="$(echo "$listing" | cut -d "\\" -f 1)"
|
|
echo "LISTING"
|
|
echo "$listing"
|
|
|
|
IFSBAK="$IFS"
|
|
IFS=$'\n'
|
|
menu $menu_listing
|
|
IFS="$IFSBAK"
|
|
|
|
menu_choice="$(0< "${dir_tmp}/${file_tmp}" )"
|
|
choice="$(echo "$listing" | grep "$menu_choice" | cut -d "\\" -f 2)"
|
|
choice_path="$(scrt_pwd)/$choice"
|
|
|
|
if [ -d "$choice_path" ]; then
|
|
scrt_cd "$choice"
|
|
scrt_menu
|
|
elif [ -f "$choice_path" ]; then
|
|
echo "$choice_path"
|
|
return
|
|
elif [[ "$menu_choice" == "" ]]; then
|
|
scrt_cd ..
|
|
echo "$current_path"
|
|
if [[ "$current_path" == "" ]] || [[ "$current_path" == ".." ]]; then
|
|
return
|
|
else
|
|
scrt_menu
|
|
fi
|
|
else
|
|
alert_message "Could not find selected item \"$menu_choice\""
|
|
fi
|
|
}
|
|
|
|
function main {
|
|
scrt_menu
|
|
}
|
|
|
|
# Run if not sourced
|
|
BASH_SOURCE=".$0"
|
|
test ".$0" != ".$BASH_SOURCE" || main $@
|