openmux 0.1.3 → 0.1.5

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.
Files changed (2) hide show
  1. package/bin/openmux +86 -56
  2. package/package.json +4 -2
package/bin/openmux CHANGED
@@ -1,43 +1,45 @@
1
1
  #!/usr/bin/env bash
2
2
  set -euo pipefail
3
3
 
4
- # openmux npm bin wrapper
5
- # Downloads binary on first run if missing, then executes
4
+ # openmux npm/bun bin wrapper
5
+ # Downloads binary to ~/.openmux/bin/ on first run if missing
6
6
 
7
7
  REPO="monotykamary/openmux"
8
+ OPENMUX_HOME="${OPENMUX_HOME:-$HOME/.openmux}"
9
+ BIN_DIR="$OPENMUX_HOME/bin"
8
10
 
9
- # Find the package directory - check multiple possible locations
10
- find_package_dir() {
11
+ # Find package.json to get version
12
+ find_package_json() {
11
13
  local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12
14
 
13
- # Check if we're in the package's bin directory (npm/yarn symlink)
15
+ # Check if we're in the package's bin directory
14
16
  if [[ -f "$(dirname "$script_dir")/package.json" ]]; then
15
- echo "$(dirname "$script_dir")"
17
+ echo "$(dirname "$script_dir")/package.json"
16
18
  return
17
19
  fi
18
20
 
19
- # Bun global: ~/.bun/install/global/node_modules/openmux
20
- if [[ -d "$HOME/.bun/install/global/node_modules/openmux" ]]; then
21
- echo "$HOME/.bun/install/global/node_modules/openmux"
21
+ # Bun global
22
+ if [[ -f "$HOME/.bun/install/global/node_modules/openmux/package.json" ]]; then
23
+ echo "$HOME/.bun/install/global/node_modules/openmux/package.json"
22
24
  return
23
25
  fi
24
26
 
25
- # npm global (macOS/Linux)
27
+ # npm global
26
28
  local npm_prefix
27
29
  npm_prefix="$(npm prefix -g 2>/dev/null || echo "")"
28
- if [[ -n "$npm_prefix" && -d "$npm_prefix/lib/node_modules/openmux" ]]; then
29
- echo "$npm_prefix/lib/node_modules/openmux"
30
+ if [[ -n "$npm_prefix" && -f "$npm_prefix/lib/node_modules/openmux/package.json" ]]; then
31
+ echo "$npm_prefix/lib/node_modules/openmux/package.json"
30
32
  return
31
33
  fi
32
34
 
33
- # Fallback: search common locations
35
+ # Fallback locations
34
36
  local locations=(
35
- "/usr/local/lib/node_modules/openmux"
36
- "/usr/lib/node_modules/openmux"
37
- "$HOME/.npm-global/lib/node_modules/openmux"
37
+ "/usr/local/lib/node_modules/openmux/package.json"
38
+ "/usr/lib/node_modules/openmux/package.json"
39
+ "$HOME/.npm-global/lib/node_modules/openmux/package.json"
38
40
  )
39
41
  for loc in "${locations[@]}"; do
40
- if [[ -d "$loc" ]]; then
42
+ if [[ -f "$loc" ]]; then
41
43
  echo "$loc"
42
44
  return
43
45
  fi
@@ -47,7 +49,7 @@ find_package_dir() {
47
49
  }
48
50
 
49
51
  get_version() {
50
- local pkg_json="$1/package.json"
52
+ local pkg_json="$1"
51
53
  if [[ -f "$pkg_json" ]]; then
52
54
  grep '"version"' "$pkg_json" | head -1 | sed 's/.*"version": *"\([^"]*\)".*/\1/'
53
55
  else
@@ -75,61 +77,66 @@ get_platform() {
75
77
  echo "${os}-${arch}"
76
78
  }
77
79
 
80
+ spinner() {
81
+ local pid=$1
82
+ local spin='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'
83
+ local i=0
84
+ while kill -0 "$pid" 2>/dev/null; do
85
+ printf "\r %s %s" "${spin:i++%${#spin}:1}" "$2"
86
+ sleep 0.1
87
+ done
88
+ printf "\r"
89
+ }
90
+
78
91
  download_binary() {
79
- local package_dir="$1"
80
- local dist_dir="$package_dir/dist"
81
- local version="v$(get_version "$package_dir")"
92
+ local version="$1"
82
93
  local platform="$(get_platform)"
83
94
 
84
- if [[ -z "$version" || "$version" == "v" ]]; then
85
- echo "Error: Could not determine openmux version" >&2
86
- return 1
87
- fi
88
-
89
95
  if [[ -z "$platform" ]]; then
90
96
  echo "Error: Unsupported platform" >&2
91
97
  return 1
92
98
  fi
93
99
 
94
- local url="https://github.com/$REPO/releases/download/$version/openmux-$version-$platform.tar.gz"
100
+ local url="https://github.com/$REPO/releases/download/v$version/openmux-v$version-$platform.tar.gz"
95
101
 
96
- echo "Downloading openmux $version for $platform..."
97
- echo "From: $url"
102
+ printf "\n"
103
+ printf " \033[1mopenmux\033[0m v%s\n" "$version"
104
+ printf " Setting up for first run...\n"
105
+ printf "\n"
98
106
 
99
- mkdir -p "$dist_dir"
100
- local tmp_file="$dist_dir/download.tar.gz"
107
+ mkdir -p "$BIN_DIR"
108
+ local tmp_file="$BIN_DIR/download.tar.gz"
101
109
 
102
- # Download
110
+ # Download with spinner
103
111
  if command -v curl &>/dev/null; then
104
- curl -fsSL "$url" -o "$tmp_file" || return 1
112
+ curl -fsSL "$url" -o "$tmp_file" 2>/dev/null &
105
113
  elif command -v wget &>/dev/null; then
106
- wget -q "$url" -O "$tmp_file" || return 1
114
+ wget -q "$url" -O "$tmp_file" 2>/dev/null &
107
115
  else
108
116
  echo "Error: curl or wget required" >&2
109
117
  return 1
110
118
  fi
111
-
112
- # Extract
113
- echo "Extracting..."
114
- tar -xzf "$tmp_file" -C "$dist_dir"
119
+ spinner $! "Downloading..."
120
+ wait $! || { printf " \033[31mDownload failed\033[0m\n"; return 1; }
121
+ printf " \033[32m✓\033[0m Downloaded\n"
122
+
123
+ # Extract with spinner
124
+ tar -xzf "$tmp_file" -C "$BIN_DIR" &
125
+ spinner $! "Extracting..."
126
+ wait $!
115
127
  rm -f "$tmp_file"
128
+ printf " \033[32m✓\033[0m Extracted\n"
116
129
 
117
130
  # Make executable
118
- chmod +x "$dist_dir/openmux-bin" 2>/dev/null || true
119
- chmod +x "$dist_dir/openmux" 2>/dev/null || true
120
-
121
- echo "Ready!"
122
- echo ""
123
- }
131
+ chmod +x "$BIN_DIR/openmux-bin" 2>/dev/null || true
124
132
 
125
- PACKAGE_DIR="$(find_package_dir)"
133
+ # Write version file for upgrade detection
134
+ echo "$version" > "$BIN_DIR/.version"
126
135
 
127
- if [[ -z "$PACKAGE_DIR" ]]; then
128
- echo "Error: Could not find openmux package directory" >&2
129
- exit 1
130
- fi
131
-
132
- DIST_DIR="$PACKAGE_DIR/dist"
136
+ printf "\n"
137
+ printf " \033[32mReady!\033[0m Starting openmux...\n"
138
+ printf "\n"
139
+ }
133
140
 
134
141
  # Determine library extension based on OS
135
142
  case "$(uname -s)" in
@@ -138,11 +145,34 @@ case "$(uname -s)" in
138
145
  *) echo "Unsupported OS" >&2; exit 1 ;;
139
146
  esac
140
147
 
141
- # Download binary if missing
142
- if [[ ! -x "$DIST_DIR/openmux-bin" ]]; then
143
- download_binary "$PACKAGE_DIR" || exit 1
148
+ # Get package version
149
+ PKG_JSON="$(find_package_json)"
150
+ if [[ -z "$PKG_JSON" ]]; then
151
+ # Fallback: if binary exists, just run it
152
+ if [[ -x "$BIN_DIR/openmux-bin" ]]; then
153
+ export BUN_PTY_LIB="${BUN_PTY_LIB:-$BIN_DIR/librust_pty.$LIB_EXT}"
154
+ exec "$BIN_DIR/openmux-bin" "$@"
155
+ fi
156
+ echo "Error: Could not find openmux package" >&2
157
+ exit 1
158
+ fi
159
+
160
+ VERSION="$(get_version "$PKG_JSON")"
161
+ if [[ -z "$VERSION" ]]; then
162
+ echo "Error: Could not determine openmux version" >&2
163
+ exit 1
164
+ fi
165
+
166
+ # Check if binary exists and matches version
167
+ INSTALLED_VERSION=""
168
+ if [[ -f "$BIN_DIR/.version" ]]; then
169
+ INSTALLED_VERSION="$(cat "$BIN_DIR/.version")"
170
+ fi
171
+
172
+ if [[ ! -x "$BIN_DIR/openmux-bin" ]] || [[ "$INSTALLED_VERSION" != "$VERSION" ]]; then
173
+ download_binary "$VERSION" || exit 1
144
174
  fi
145
175
 
146
176
  # Set library path and execute
147
- export BUN_PTY_LIB="${BUN_PTY_LIB:-$DIST_DIR/librust_pty.$LIB_EXT}"
148
- exec "$DIST_DIR/openmux-bin" "$@"
177
+ export BUN_PTY_LIB="${BUN_PTY_LIB:-$BIN_DIR/librust_pty.$LIB_EXT}"
178
+ exec "$BIN_DIR/openmux-bin" "$@"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openmux",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Terminal multiplexer with master-stack tiling layout",
5
5
  "module": "src/index.tsx",
6
6
  "type": "module",
@@ -9,7 +9,9 @@
9
9
  },
10
10
  "files": [
11
11
  "bin",
12
- "scripts/postinstall.cjs"
12
+ "scripts/postinstall.cjs",
13
+ "README.md",
14
+ "LICENSE"
13
15
  ],
14
16
  "scripts": {
15
17
  "start": "bun run src/index.tsx",