Skip to content

Commit 7e3278e

Browse files
Copilotbytemain
andauthored
feat: add --user flag to install.sh for user-local installation (#586)
* Initial plan * Add --user flag to install.sh for user-local installation Co-authored-by: bytemain <13938334+bytemain@users.noreply.github.com> * Improve code quality: use POSIX-compliant pattern matching and reduce duplication Co-authored-by: bytemain <13938334+bytemain@users.noreply.github.com> * Remove trailing whitespace Co-authored-by: bytemain <13938334+bytemain@users.noreply.github.com> * Improve shell detection and fish instructions Co-authored-by: bytemain <13938334+bytemain@users.noreply.github.com> * Update documentation with --user flag usage Co-authored-by: bytemain <13938334+bytemain@users.noreply.github.com> * Use $INSTALL_DIR variable instead of hardcoded path in fish instructions Co-authored-by: bytemain <13938334+bytemain@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bytemain <13938334+bytemain@users.noreply.github.com>
1 parent c8e8f25 commit 7e3278e

3 files changed

Lines changed: 100 additions & 1 deletion

File tree

docs/guides/quick-start.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ sudo yum install vfox
7171
$ curl -sSL https://raw.githubusercontent.com/version-fox/vfox/main/install.sh | bash
7272
```
7373

74+
**User-local Installation (no sudo required)**
75+
76+
If you want to install `vfox` to your user directory (`~/.local/bin`) instead of system-wide, use the `--user` flag. This is particularly useful for environments where you don't have sudo access or where system directories are ephemeral (e.g., Coder workspaces):
77+
78+
```shell
79+
$ curl -sSL https://raw.githubusercontent.com/version-fox/vfox/main/install.sh | bash -s -- --user
80+
```
81+
82+
This will:
83+
- Install `vfox` to `~/.local/bin` (no sudo required)
84+
- Automatically create the directory if it doesn't exist
85+
- Provide instructions to add `~/.local/bin` to your `PATH` if needed
86+
7487
:::
7588

7689
## 2. Hook `vfox` to your `Shell`

docs/zh-hans/guides/quick-start.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ sudo yum install vfox
7272
$ curl -sSL https://raw.githubusercontent.com/version-fox/vfox/main/install.sh | bash
7373
```
7474

75+
**用户级安装(无需 sudo)**
76+
77+
如果您想将 `vfox` 安装到用户目录(`~/.local/bin`)而不是系统范围内,请使用 `--user` 标志。这对于没有 sudo 访问权限或系统目录为临时目录的环境(例如 Coder 工作区)特别有用:
78+
79+
```shell
80+
$ curl -sSL https://raw.githubusercontent.com/version-fox/vfox/main/install.sh | bash -s -- --user
81+
```
82+
83+
此命令将:
84+
-`vfox` 安装到 `~/.local/bin`(无需 sudo)
85+
- 如果目录不存在,会自动创建
86+
- 如果需要,会提供将 `~/.local/bin` 添加到 `PATH` 的说明
87+
7588
:::
7689

7790
## 2. 挂载`vfox`到你的`Shell`

install.sh

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
#!/bin/bash
22

33
main() {
4+
# Parse command-line arguments
5+
USER_INSTALL=false
6+
for arg in "$@"; do
7+
case "$arg" in
8+
--user)
9+
USER_INSTALL=true
10+
;;
11+
*)
12+
echo "Unknown argument: $arg"
13+
echo "Usage: $0 [--user]"
14+
exit 1
15+
;;
16+
esac
17+
done
18+
419
# Detect if running in Termux
520
IS_TERMUX=false
621
case "${HOME:-}" in
@@ -11,7 +26,11 @@ main() {
1126
esac
1227

1328
# Set installation directory and sudo command based on environment
14-
if [ "$IS_TERMUX" = true ]; then
29+
if [ "$USER_INSTALL" = true ]; then
30+
INSTALL_DIR="${HOME}/.local/bin"
31+
SUDO_CMD=""
32+
echo "Installing to user directory: $INSTALL_DIR"
33+
elif [ "$IS_TERMUX" = true ]; then
1534
INSTALL_DIR="${PREFIX}/bin"
1635
SUDO_CMD=""
1736
else
@@ -105,6 +124,60 @@ main() {
105124
rm $TAR_FILE
106125
rm -rf $FILENAME
107126
echo "vfox installed successfully!"
127+
128+
# Check and update PATH if installing to user directory
129+
if [ "$USER_INSTALL" = true ]; then
130+
# Check if ~/.local/bin is in PATH using POSIX-compliant pattern matching
131+
case ":$PATH:" in
132+
*":$INSTALL_DIR:"*)
133+
echo "$INSTALL_DIR is already in your PATH."
134+
;;
135+
*)
136+
echo ""
137+
echo "WARNING: $INSTALL_DIR is not in your PATH."
138+
echo "To add it to your PATH, run one of the following commands based on your shell:"
139+
echo ""
140+
141+
# Common export command for bash/zsh
142+
PATH_EXPORT_CMD='export PATH="$HOME/.local/bin:$PATH"'
143+
144+
# Detect the current shell more reliably than using $SHELL alone
145+
if command -v ps >/dev/null 2>&1; then
146+
CURRENT_SHELL=$(ps -p "$$" -o comm= 2>/dev/null | tr -d ' ')
147+
fi
148+
if [ -z "$CURRENT_SHELL" ] && [ -n "$SHELL" ]; then
149+
CURRENT_SHELL=$(basename "$SHELL")
150+
fi
151+
152+
case "$CURRENT_SHELL" in
153+
bash)
154+
echo " For bash:"
155+
echo " echo '$PATH_EXPORT_CMD' >> ~/.bashrc"
156+
echo " source ~/.bashrc"
157+
;;
158+
zsh)
159+
echo " For zsh:"
160+
echo " echo '$PATH_EXPORT_CMD' >> ~/.zshrc"
161+
echo " source ~/.zshrc"
162+
;;
163+
fish)
164+
echo " For fish:"
165+
echo " # Run this in a fish shell:"
166+
echo " fish_add_path $INSTALL_DIR"
167+
echo " # Or persist it by adding this line to your config:"
168+
echo " echo 'fish_add_path $INSTALL_DIR' >> ~/.config/fish/config.fish"
169+
;;
170+
*)
171+
echo " For bash/zsh:"
172+
echo " echo '$PATH_EXPORT_CMD' >> ~/.bashrc # or ~/.zshrc"
173+
echo " source ~/.bashrc # or source ~/.zshrc"
174+
;;
175+
esac
176+
echo ""
177+
echo "Or manually add $INSTALL_DIR to your PATH in your shell's configuration file."
178+
;;
179+
esac
180+
fi
108181
}
109182

110183
main "$@"

0 commit comments

Comments
 (0)