openmux 0.1.4 → 0.1.6

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 +58 -47
  2. package/package.json +1 -1
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
@@ -87,30 +89,23 @@ spinner() {
87
89
  }
88
90
 
89
91
  download_binary() {
90
- local package_dir="$1"
91
- local dist_dir="$package_dir/dist"
92
- local version="v$(get_version "$package_dir")"
92
+ local version="$1"
93
93
  local platform="$(get_platform)"
94
94
 
95
- if [[ -z "$version" || "$version" == "v" ]]; then
96
- echo "Error: Could not determine openmux version" >&2
97
- return 1
98
- fi
99
-
100
95
  if [[ -z "$platform" ]]; then
101
96
  echo "Error: Unsupported platform" >&2
102
97
  return 1
103
98
  fi
104
99
 
105
- 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"
106
101
 
107
102
  printf "\n"
108
- printf " \033[1mopenmux\033[0m %s\n" "$version"
103
+ printf " \033[1mopenmux\033[0m v%s\n" "$version"
109
104
  printf " Setting up for first run...\n"
110
105
  printf "\n"
111
106
 
112
- mkdir -p "$dist_dir"
113
- local tmp_file="$dist_dir/download.tar.gz"
107
+ mkdir -p "$BIN_DIR"
108
+ local tmp_file="$BIN_DIR/download.tar.gz"
114
109
 
115
110
  # Download with spinner
116
111
  if command -v curl &>/dev/null; then
@@ -126,30 +121,23 @@ download_binary() {
126
121
  printf " \033[32m✓\033[0m Downloaded\n"
127
122
 
128
123
  # Extract with spinner
129
- tar -xzf "$tmp_file" -C "$dist_dir" &
124
+ tar -xzf "$tmp_file" -C "$BIN_DIR" &
130
125
  spinner $! "Extracting..."
131
126
  wait $!
132
127
  rm -f "$tmp_file"
133
128
  printf " \033[32m✓\033[0m Extracted\n"
134
129
 
135
130
  # Make executable
136
- chmod +x "$dist_dir/openmux-bin" 2>/dev/null || true
137
- chmod +x "$dist_dir/openmux" 2>/dev/null || true
131
+ chmod +x "$BIN_DIR/openmux-bin" 2>/dev/null || true
132
+
133
+ # Write version file for upgrade detection
134
+ echo "$version" > "$BIN_DIR/.version"
138
135
 
139
136
  printf "\n"
140
137
  printf " \033[32mReady!\033[0m Starting openmux...\n"
141
138
  printf "\n"
142
139
  }
143
140
 
144
- PACKAGE_DIR="$(find_package_dir)"
145
-
146
- if [[ -z "$PACKAGE_DIR" ]]; then
147
- echo "Error: Could not find openmux package directory" >&2
148
- exit 1
149
- fi
150
-
151
- DIST_DIR="$PACKAGE_DIR/dist"
152
-
153
141
  # Determine library extension based on OS
154
142
  case "$(uname -s)" in
155
143
  Darwin) LIB_EXT="dylib" ;;
@@ -157,11 +145,34 @@ case "$(uname -s)" in
157
145
  *) echo "Unsupported OS" >&2; exit 1 ;;
158
146
  esac
159
147
 
160
- # Download binary if missing
161
- if [[ ! -x "$DIST_DIR/openmux-bin" ]]; then
162
- 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
163
174
  fi
164
175
 
165
176
  # Set library path and execute
166
- export BUN_PTY_LIB="${BUN_PTY_LIB:-$DIST_DIR/librust_pty.$LIB_EXT}"
167
- 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.4",
3
+ "version": "0.1.6",
4
4
  "description": "Terminal multiplexer with master-stack tiling layout",
5
5
  "module": "src/index.tsx",
6
6
  "type": "module",