easy-command 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 UnionSchool
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,150 @@
1
+ # easy-command
2
+
3
+ One command to configure a polished Zsh terminal with Oh My Zsh, the `agnoster` theme, Git status, command suggestions, Tab completion, and syntax highlighting.
4
+
5
+ > 一条命令配置统一的 Zsh 终端:Oh My Zsh、`agnoster` 主题、Git 状态、历史命令建议、Tab 补全与命令语法高亮。
6
+
7
+ ## Preview
8
+
9
+ > 效果预览。
10
+
11
+ ### Git branch and working-tree status
12
+
13
+ > Git 分支与工作区状态。
14
+
15
+ ![agnoster displays Git branch and working-tree status](assets/git-status.png)
16
+
17
+ ### History-based command suggestions
18
+
19
+ > 历史命令自动建议。
20
+
21
+ ![A suggested history command appears while typing](assets/autosuggestions.png)
22
+
23
+ ### Syntax highlighting and error feedback
24
+
25
+ > 命令语法高亮与错误提示。
26
+
27
+ ![Valid commands are green and unknown commands are red](assets/syntax-highlighting.png)
28
+
29
+ ## Quick start
30
+
31
+ > 快速开始。
32
+
33
+ Install the latest version:
34
+
35
+ > 安装最新版本:
36
+
37
+ ```bash
38
+ npx easy-command --yes
39
+ ```
40
+
41
+ Or install directly from GitHub without Node.js/npm:
42
+
43
+ > 或者无需 Node.js/npm,直接从 GitHub 安装:
44
+
45
+ ```bash
46
+ curl -fsSL https://raw.githubusercontent.com/UnionSchool/easy-command/main/install.sh | bash -s -- --yes
47
+ ```
48
+
49
+ After installation, sign in again or run:
50
+
51
+ > 安装完成后重新登录,或运行:
52
+
53
+ ```bash
54
+ exec zsh -l
55
+ ```
56
+
57
+ ## What you get
58
+
59
+ > 提供的能力。
60
+
61
+ - `agnoster`: shows the user, current path, Git branch, and working-tree status.<br>
62
+ `agnoster`:显示用户名、路径、Git 分支和工作区状态。
63
+ - `zsh-autosuggestions`: shows gray suggestions from command history; press `→` or `Ctrl+E` to accept.<br>
64
+ `zsh-autosuggestions`:从历史命令显示灰色建议,按 `→` 或 `Ctrl+E` 接受。
65
+ - `zsh-syntax-highlighting`: valid commands are green; unknown commands are bold red.<br>
66
+ `zsh-syntax-highlighting`:有效命令绿色、未知命令红色加粗。
67
+ - Native Zsh completion: press `Tab` to complete commands, paths, and Git subcommands; press it twice for candidates.<br>
68
+ Zsh 原生补全:按 `Tab` 补全命令、路径和 Git 子命令,连按两次显示候选项。
69
+ - Shared history: the latest 10,000 commands are shared between terminal sessions.<br>
70
+ 共享历史:多个终端会话共享最近 10,000 条命令。
71
+
72
+ ## Options
73
+
74
+ > 参数。
75
+
76
+ ```bash
77
+ # Configure a specific user / 指定目标用户
78
+ bash install.sh --yes --user bell
79
+
80
+ # Keep the current login shell / 不改变默认登录 Shell
81
+ bash install.sh --yes --no-chsh
82
+
83
+ # Remove only the configuration block managed by easy-command / 删除本工具管理的 .zshrc 区块
84
+ bash install.sh --uninstall
85
+ ```
86
+
87
+ ## Supported platforms
88
+
89
+ > 支持范围。
90
+
91
+ - macOS: Homebrew must already be installed.<br>
92
+ macOS:要求已安装 Homebrew。
93
+ - Ubuntu / Debian: dependencies are installed with `apt-get`.<br>
94
+ Ubuntu / Debian:使用 `apt-get` 安装依赖。
95
+
96
+ The script needs `sudo` to install packages and change the default shell. Without sudo access, use `--no-chsh` and have an administrator install Zsh first.
97
+
98
+ > 脚本需要 `sudo` 来安装软件包和切换默认 Shell。没有 sudo 权限时,可加 `--no-chsh`,并由管理员预先安装 Zsh。
99
+
100
+ ## Configuration and rollback
101
+
102
+ > 配置与回退。
103
+
104
+ Installed files:
105
+
106
+ > 安装内容位于:
107
+
108
+ ```text
109
+ ~/.easy-command/oh-my-zsh
110
+ ~/.zshrc
111
+ ~/.zsh_history
112
+ ```
113
+
114
+ Before each `.zshrc` update, the script creates a timestamped backup. `--uninstall` removes only the configuration block managed by easy-command; it does not remove Oh My Zsh, plugins, or other user settings.
115
+
116
+ > 每次更新 `.zshrc` 前,脚本会创建带时间戳的备份。`--uninstall` 只删除由 easy-command 管理的配置块,不会删除 Oh My Zsh、插件或用户自己的其他配置。
117
+
118
+ ## Security
119
+
120
+ > 安全说明。
121
+
122
+ For a first-time trial, download and inspect the script before running it:
123
+
124
+ > 首次试用建议先下载并审阅脚本:
125
+
126
+ ```bash
127
+ curl -fsSLO https://raw.githubusercontent.com/UnionSchool/easy-command/main/install.sh
128
+ less install.sh
129
+ bash install.sh --yes
130
+ ```
131
+
132
+ For production, pin a release tag instead of running `main` directly:
133
+
134
+ > 生产环境建议固定到发布标签,而不是直接使用 `main`:
135
+
136
+ ```bash
137
+ npx easy-command@1.0.4 --yes
138
+ ```
139
+
140
+ Or, without npm:
141
+
142
+ > 或者不使用 npm:
143
+
144
+ ```bash
145
+ curl -fsSL https://raw.githubusercontent.com/UnionSchool/easy-command/v1.0.4/install.sh | bash -s -- --yes
146
+ ```
147
+
148
+ ## License
149
+
150
+ [MIT](LICENSE)
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -Eeuo pipefail
4
+
5
+ source_path="${BASH_SOURCE[0]}"
6
+ while [[ -h "$source_path" ]]; do
7
+ source_directory="$(cd -P "$(dirname "$source_path")" && pwd)"
8
+ source_path="$(readlink "$source_path")"
9
+ [[ "$source_path" == /* ]] || source_path="$source_directory/$source_path"
10
+ done
11
+
12
+ package_directory="$(cd -P "$(dirname "$source_path")/.." && pwd)"
13
+ exec "$package_directory/install.sh" "$@"
package/install.sh ADDED
@@ -0,0 +1,200 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -Eeuo pipefail
4
+
5
+ readonly VERSION='1.0.4'
6
+ readonly BEGIN_MARKER='# >>> easy-command zsh >>>'
7
+ readonly END_MARKER='# <<< easy-command zsh <<<'
8
+
9
+ ASSUME_YES=false
10
+ CHANGE_LOGIN_SHELL=true
11
+ UNINSTALL=false
12
+ TARGET_USER="${SUDO_USER:-${USER}}"
13
+
14
+ info() { printf '\033[1;32m[easy-command]\033[0m %s\n' "$*"; }
15
+ warn() { printf '\033[1;33m[easy-command]\033[0m %s\n' "$*" >&2; }
16
+ fail() { printf '\033[1;31m[easy-command]\033[0m %s\n' "$*" >&2; exit 1; }
17
+
18
+ usage() {
19
+ cat <<'EOF'
20
+ Usage: install.sh [options]
21
+
22
+ Options:
23
+ --yes, -y Run without confirmation.
24
+ --user USER Configure this user. Defaults to the invoking user.
25
+ --no-chsh Do not change the user's default login shell to zsh.
26
+ --uninstall Remove only the easy-command managed .zshrc block.
27
+ --help, -h Show this help.
28
+ EOF
29
+ }
30
+
31
+ while (($#)); do
32
+ case "$1" in
33
+ --yes|-y) ASSUME_YES=true ;;
34
+ --user)
35
+ shift
36
+ (($#)) || fail '--user requires a value.'
37
+ TARGET_USER="$1"
38
+ ;;
39
+ --no-chsh) CHANGE_LOGIN_SHELL=false ;;
40
+ --uninstall) UNINSTALL=true ;;
41
+ --help|-h)
42
+ usage
43
+ exit 0
44
+ ;;
45
+ *) fail "Unknown option: $1" ;;
46
+ esac
47
+ shift
48
+ done
49
+
50
+ TARGET_HOME="$(getent passwd "$TARGET_USER" | cut -d: -f6 2>/dev/null || true)"
51
+ if [[ -z "$TARGET_HOME" && "$(uname -s)" == 'Darwin' ]]; then
52
+ TARGET_HOME="$(dscl . -read "/Users/$TARGET_USER" NFSHomeDirectory | awk '{print $2}')"
53
+ fi
54
+ [[ -n "$TARGET_HOME" && -d "$TARGET_HOME" ]] || fail "Cannot determine home directory for $TARGET_USER."
55
+
56
+ run_as_root() {
57
+ if [[ "$EUID" -eq 0 ]]; then
58
+ "$@"
59
+ elif command -v sudo >/dev/null 2>&1; then
60
+ sudo "$@"
61
+ else
62
+ fail 'sudo is required to install packages or change the login shell.'
63
+ fi
64
+ }
65
+
66
+ run_as_user() {
67
+ if [[ "$EUID" -eq 0 && "$TARGET_USER" != 'root' ]]; then
68
+ runuser -u "$TARGET_USER" -- "$@"
69
+ else
70
+ "$@"
71
+ fi
72
+ }
73
+
74
+ backup_file() {
75
+ local file="$1"
76
+ [[ -f "$file" ]] || return 0
77
+
78
+ local backup="${file}.easy-command-backup-$(date +%Y%m%d%H%M%S)"
79
+ cp "$file" "$backup"
80
+ info "Backed up $file to $backup"
81
+ }
82
+
83
+ remove_managed_block() {
84
+ local zshrc="$TARGET_HOME/.zshrc"
85
+ [[ -f "$zshrc" ]] || return 0
86
+
87
+ local temp_file
88
+ temp_file="$(mktemp)"
89
+ awk -v begin="$BEGIN_MARKER" -v end="$END_MARKER" '
90
+ $0 == begin { skipping = 1; next }
91
+ $0 == end { skipping = 0; next }
92
+ !skipping { print }
93
+ ' "$zshrc" > "$temp_file"
94
+ cat "$temp_file" > "$zshrc"
95
+ rm -f "$temp_file"
96
+ chown "$TARGET_USER" "$zshrc" 2>/dev/null || true
97
+ }
98
+
99
+ install_packages() {
100
+ case "$(uname -s)" in
101
+ Darwin)
102
+ command -v brew >/dev/null 2>&1 || fail 'Homebrew is required on macOS: https://brew.sh'
103
+ brew install zsh git
104
+ ;;
105
+ Linux)
106
+ command -v apt-get >/dev/null 2>&1 || fail 'Only Ubuntu/Debian (apt-get) is supported on Linux.'
107
+ run_as_root apt-get update
108
+ run_as_root env DEBIAN_FRONTEND=noninteractive apt-get install -y zsh git
109
+ ;;
110
+ *) fail "Unsupported operating system: $(uname -s)" ;;
111
+ esac
112
+ }
113
+
114
+ install_repository() {
115
+ local repository="$1"
116
+ local destination="$2"
117
+ [[ -d "$destination/.git" ]] && return 0
118
+
119
+ mkdir -p "$(dirname "$destination")"
120
+ run_as_user git clone --depth 1 "$repository" "$destination"
121
+ }
122
+
123
+ write_zshrc_block() {
124
+ local zshrc="$TARGET_HOME/.zshrc"
125
+ local temp_file
126
+ temp_file="$(mktemp)"
127
+
128
+ [[ -f "$zshrc" ]] && awk -v begin="$BEGIN_MARKER" -v end="$END_MARKER" '
129
+ $0 == begin { skipping = 1; next }
130
+ $0 == end { skipping = 0; next }
131
+ !skipping { print }
132
+ ' "$zshrc" > "$temp_file"
133
+
134
+ cat >> "$temp_file" <<'EOF'
135
+
136
+ # >>> easy-command zsh >>>
137
+ # Managed by easy-command. Re-run the installer to update this block.
138
+ export ZSH="$HOME/.easy-command/oh-my-zsh"
139
+ ZSH_THEME="agnoster"
140
+ plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
141
+
142
+ HISTFILE="$HOME/.zsh_history"
143
+ HISTSIZE=10000
144
+ SAVEHIST=10000
145
+ setopt append_history share_history hist_ignore_dups
146
+ ZSH_AUTOSUGGEST_STRATEGY=(history completion)
147
+ ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8'
148
+
149
+ source "$ZSH/oh-my-zsh.sh"
150
+
151
+ ZSH_HIGHLIGHT_STYLES[command]='fg=green'
152
+ ZSH_HIGHLIGHT_STYLES[builtin]='fg=green'
153
+ ZSH_HIGHLIGHT_STYLES[function]='fg=green'
154
+ ZSH_HIGHLIGHT_STYLES[alias]='fg=green'
155
+ ZSH_HIGHLIGHT_STYLES[unknown-token]='fg=red,bold'
156
+ # <<< easy-command zsh <<<
157
+ EOF
158
+
159
+ backup_file "$zshrc"
160
+ cat "$temp_file" > "$zshrc"
161
+ rm -f "$temp_file"
162
+ chown "$TARGET_USER" "$zshrc" 2>/dev/null || true
163
+ }
164
+
165
+ change_login_shell() {
166
+ "$CHANGE_LOGIN_SHELL" || return 0
167
+
168
+ local zsh_path
169
+ zsh_path="$(command -v zsh)"
170
+ grep -qx "$zsh_path" /etc/shells || fail "$zsh_path is not listed in /etc/shells."
171
+ run_as_root chsh -s "$zsh_path" "$TARGET_USER"
172
+ }
173
+
174
+ main() {
175
+ if "$UNINSTALL"; then
176
+ backup_file "$TARGET_HOME/.zshrc"
177
+ remove_managed_block
178
+ info 'Removed the easy-command managed .zshrc block.'
179
+ exit 0
180
+ fi
181
+
182
+ if ! "$ASSUME_YES"; then
183
+ read -r -p "Install easy-command for $TARGET_USER? [y/N] " answer
184
+ [[ "$answer" =~ ^[Yy]$ ]] || exit 0
185
+ fi
186
+
187
+ install_packages
188
+
189
+ local base_dir="$TARGET_HOME/.easy-command"
190
+ install_repository 'https://github.com/ohmyzsh/ohmyzsh.git' "$base_dir/oh-my-zsh"
191
+ install_repository 'https://github.com/zsh-users/zsh-autosuggestions.git' "$base_dir/oh-my-zsh/custom/plugins/zsh-autosuggestions"
192
+ install_repository 'https://github.com/zsh-users/zsh-syntax-highlighting.git' "$base_dir/oh-my-zsh/custom/plugins/zsh-syntax-highlighting"
193
+
194
+ write_zshrc_block
195
+ change_login_shell
196
+
197
+ info "Installed easy-command $VERSION for $TARGET_USER. Reconnect or run: exec zsh -l"
198
+ }
199
+
200
+ main
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "easy-command",
3
+ "version": "1.0.4",
4
+ "description": "Configure a polished Zsh terminal with one command.",
5
+ "license": "MIT",
6
+ "bin": {
7
+ "easy-command": "bin/easy-command"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "install.sh",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/UnionSchool/easy-command.git"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/UnionSchool/easy-command/issues"
21
+ },
22
+ "homepage": "https://github.com/UnionSchool/easy-command#readme",
23
+ "keywords": [
24
+ "zsh",
25
+ "oh-my-zsh",
26
+ "terminal",
27
+ "cli",
28
+ "installer"
29
+ ],
30
+ "engines": {
31
+ "node": ">=18"
32
+ }
33
+ }