-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·154 lines (138 loc) · 4.7 KB
/
install.sh
File metadata and controls
executable file
·154 lines (138 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
# Check if running in local test mode
# When --local or -l flag is provided, the script will copy the local code-nautilus.py
# instead of downloading from GitHub. This is useful for testing local changes.
LOCAL_MODE=false
if [ "$1" = "--local" ] || [ "$1" = "-l" ]; then
LOCAL_MODE=true
echo "Local test mode enabled"
fi
# Helper function to ask yes/no questions with default answer
# Args:
# $1 - The prompt message to display
# $2 - The default answer (Y or N)
# Returns:
# 0 for yes, 1 for no
ask_yes_no() {
local prompt="$1"
local default_answer="$2"
local reply
while true
do
read -r -p "$prompt" reply
if [ -z "$reply" ]
then
reply="$default_answer"
fi
case "$reply" in
[yY]) return 0 ;;
[nN]) return 1 ;;
*) echo "Please enter y or n." ;;
esac
done
}
# Configure which VS Code versions to register in Nautilus context menu
# Creates a configuration file that the Python extension reads to determine
# which VS Code variants should appear in the right-click menu.
# Configuration is saved to ~/.config/code-nautilus/targets.conf
configure_targets() {
local config_dir="$HOME/.config/code-nautilus"
local config_file="$config_dir/targets.conf"
mkdir -p "$config_dir"
echo "Select VS Code version(s) to register in Nautilus:"
local register_code
local register_insiders
# Ask if user wants to register stable VS Code
if ask_yes_no " - Register stable VS Code (code)? [Y/n] " "Y"
then
register_code=1
else
register_code=0
fi
# Ask if user wants to register VS Code Insiders
if ask_yes_no " - Register VS Code Insiders (code-insiders)? [y/N] " "N"
then
register_insiders=1
else
register_insiders=0
fi
# If neither version is selected, default to stable version
if [ "$register_code" -eq 0 ] && [ "$register_insiders" -eq 0 ]
then
echo "No version selected. Defaulting to stable VS Code."
register_code=1
fi
# Write configuration file
# Format: key=value where value is 1 (enabled) or 0 (disabled)
cat > "$config_file" <<EOF
# VS Code Nautilus Extension Configuration
# Set to 1 to enable, 0 to disable
code=$register_code
code-insiders=$register_insiders
EOF
echo "Configuration saved to $config_file"
}
# Install python-nautilus dependency
# This package is required for Nautilus to load Python extensions
echo "Installing python-nautilus..."
if type "pacman" > /dev/null 2>&1
then
# Arch Linux / Manjaro
if ! pacman -Qi python-nautilus &> /dev/null
then
sudo pacman -S --noconfirm python-nautilus
else
echo "python-nautilus is already installed"
fi
elif type "apt-get" > /dev/null 2>&1
then
# Debian / Ubuntu
# Package name varies by Ubuntu version (python-nautilus vs python3-nautilus)
package_name="python-nautilus"
found_package=$(apt-cache search --names-only $package_name)
if [ -z "$found_package" ]
then
package_name="python3-nautilus"
fi
# Check if the package is already installed
installed=$(apt list --installed $package_name -qq 2> /dev/null)
if [ -z "$installed" ]
then
sudo apt-get install -y $package_name
else
echo "$package_name is already installed."
fi
elif type "dnf" > /dev/null 2>&1
then
# Fedora / RHEL
installed=`dnf list --installed nautilus-python 2> /dev/null`
if [ -z "$installed" ]
then
sudo dnf install -y nautilus-python
else
echo "nautilus-python is already installed."
fi
else
echo "Failed to find python-nautilus, please install it manually."
fi
# Remove previous versions and ensure extension directory exists
# VSCodeExtension.py is the old filename, code-nautilus.py is the new one
echo "Removing previous version (if found)..."
mkdir -p ~/.local/share/nautilus-python/extensions
rm -f ~/.local/share/nautilus-python/extensions/VSCodeExtension.py
rm -f ~/.local/share/nautilus-python/extensions/code-nautilus.py
# Download and install the extension
# In local mode, copy from current directory; otherwise download from GitHub
if [ "$LOCAL_MODE" = true ]; then
echo "Using local version for testing..."
cp "$(dirname "$0")/code-nautilus.py" ~/.local/share/nautilus-python/extensions/code-nautilus.py
else
echo "Downloading newest version..."
wget -q -O ~/.local/share/nautilus-python/extensions/code-nautilus.py https://raw.githubusercontent.com/harry-cpp/code-nautilus/master/code-nautilus.py
fi
# Prompt user to configure which VS Code versions to register
configure_targets
# Restart Nautilus to load the new extension
echo "Restarting nautilus..."
nautilus -q
echo "Installation Complete"