Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions wsl-open.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ EnableWslCheck=${EnableWslCheck:-true}
EnableWslPath=${EnableWslPath:-true}
DryRun=${DryRun:-false}
DefaultsFile=${DefaultsFile:-~/.mailcap}
BashFile=${BashFile:-~/.bashrc}

# Error functions
Error() {
Expand All @@ -33,6 +32,15 @@ Warning() {
echo "$Exe: WARNING: $*" >&2
}

if [[ $SHELL == *"bash"* ]]; then
RcFile=${RcFile:-~/.bashrc}
elif [[ $SHELL == *"zsh"* ]]; then
RcFile=${RcFile:-~/.zshenv}
else
Warning "Unable to detect your login shell (only bash and zsh are supported), falling back to using ~/.bashrc. You can change it by setting the environment variable RcFile to the path of the source file your shell uses."
RcFile=${RcFile:~/.bashrc}
fi

# Usage message, ran on help (-h)
Usage="
.\" IMPORT wsl-open.1
Expand Down Expand Up @@ -158,10 +166,10 @@ while getopts "ha:d:wx" Opt; do
if echo "$BROWSER" | grep "$Exe" >/dev/null; then
Warning "$Exe is already set as BROWSER"
else
[[ ! -e $BashFile ]] && touch "$BashFile"
[[ ! -e $RcFile ]] && touch "$RcFile"
echo "Adding $Exe to BROWSER environmental variables"
if grep "export.*BROWSER=.*$Exe" "$BashFile" >/dev/null; then
Error "$BashFile already adds $Exe to BROWSER, check it for problems or restart your Bash"
if grep "export.*BROWSER=.*$Exe" "$RcFile" >/dev/null; then
Error "$RcFile already adds $Exe to BROWSER, check it for problems or restart your Bash"
else
echo "
# Adding $Exe as a browser for Bash for Windows
Expand All @@ -172,7 +180,7 @@ while getopts "ha:d:wx" Opt; do
export BROWSER=\$BROWSER:$Exe
fi
fi
" >>"$BashFile"
" >>"$RcFile"
fi
fi
;;
Expand Down