Skip to content

Commit de12505

Browse files
authored
Make POSIX-compliant to increase portability and remove bash depend… (microsoft#100145)
* Make POSIX-compliant to increase portability and remove `bash` dependency on Linux. Fix causes of `shellcheck` warnings. * Update resources/linux/bin/code.sh Co-authored-by: VoidNoire <18732253+VoidNoire@users.noreply.github.com> * Update resources/linux/bin/code.sh Co-authored-by: VoidNoire <18732253+VoidNoire@users.noreply.github.com> Co-authored-by: João Moreno <mail@joaomoreno.com>
2 parents fb94ca5 + 653a7af commit de12505

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

resources/linux/bin/code.sh

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
1-
#!/usr/bin/env bash
1+
#!/usr/bin/env sh
22
#
33
# Copyright (c) Microsoft Corporation. All rights reserved.
44
# Licensed under the MIT License. See License.txt in the project root for license information.
55

66
# test that VSCode wasn't installed inside WSL
77
if grep -qi Microsoft /proc/version && [ -z "$DONT_PROMPT_WSL_INSTALL" ]; then
8-
echo "To use VS Code with the Windows Subsystem for Linux, please install VS Code in Windows and uninstall the Linux version in WSL. You can then use the '@@PRODNAME@@' command in a WSL terminal just as you would in a normal command prompt." 1>&2
9-
read -e -p "Do you want to continue anyways ? [y/N] " YN
10-
11-
[[ $YN == "n" || $YN == "N" || $YN == "" ]] && exit 1
12-
echo "To no longer see this prompt, start @@PRODNAME@@ with the environment variable DONT_PROMPT_WSL_INSTALL defined."
8+
echo "To use @@PRODNAME@@ with the Windows Subsystem for Linux, please install @@PRODNAME@@ in Windows and uninstall the Linux version in WSL. You can then use the \`@@NAME@@\` command in a WSL terminal just as you would in a normal command prompt." 1>&2
9+
printf "Do you want to continue anyway? [y/N] " 1>&2
10+
read -r YN
11+
YN=$(printf '%s' "$YN" | tr '[:upper:]' '[:lower:]')
12+
case "$YN" in
13+
y | yes )
14+
;;
15+
* )
16+
exit 1
17+
;;
18+
esac
19+
echo "To no longer see this prompt, start @@PRODNAME@@ with the environment variable DONT_PROMPT_WSL_INSTALL defined." 1>&2
1320
fi
1421

15-
1622
# If root, ensure that --user-data-dir or --file-write is specified
1723
if [ "$(id -u)" = "0" ]; then
18-
for i in $@
24+
for i in "$@"
1925
do
20-
if [[ $i == --user-data-dir || $i == --user-data-dir=* || $i == --file-write ]]; then
21-
CAN_LAUNCH_AS_ROOT=1
22-
fi
26+
case "$i" in
27+
--user-data-dir | --user-data-dir=* | --file-write )
28+
CAN_LAUNCH_AS_ROOT=1
29+
;;
30+
esac
2331
done
2432
if [ -z $CAN_LAUNCH_AS_ROOT ]; then
25-
echo "You are trying to start vscode as a super user which is not recommended. If you really want to, you must specify an alternate user data directory using the --user-data-dir argument." 1>&2
33+
echo "You are trying to start @@PRODNAME@@ as a super user which isn't recommended. If this was intended, please specify an alternate user data directory using the \`--user-data-dir\` argument." 1>&2
2634
exit 1
2735
fi
2836
fi
@@ -33,7 +41,7 @@ if [ ! -L "$0" ]; then
3341
else
3442
if command -v readlink >/dev/null; then
3543
# if readlink exists, follow the symlink and find relatively
36-
VSCODE_PATH="$(dirname $(readlink -f "$0"))/.."
44+
VSCODE_PATH="$(dirname "$(readlink -f "$0")")/.."
3745
else
3846
# else use the standard install location
3947
VSCODE_PATH="/usr/share/@@NAME@@"

0 commit comments

Comments
 (0)