openmux 0.1.1 → 0.1.3

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 +128 -7
  2. package/package.json +1 -1
package/bin/openmux CHANGED
@@ -2,10 +2,133 @@
2
2
  set -euo pipefail
3
3
 
4
4
  # openmux npm bin wrapper
5
- # Locates and executes the downloaded binary
5
+ # Downloads binary on first run if missing, then executes
6
+
7
+ REPO="monotykamary/openmux"
8
+
9
+ # Find the package directory - check multiple possible locations
10
+ find_package_dir() {
11
+ local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12
+
13
+ # Check if we're in the package's bin directory (npm/yarn symlink)
14
+ if [[ -f "$(dirname "$script_dir")/package.json" ]]; then
15
+ echo "$(dirname "$script_dir")"
16
+ return
17
+ fi
18
+
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"
22
+ return
23
+ fi
24
+
25
+ # npm global (macOS/Linux)
26
+ local npm_prefix
27
+ 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
+ return
31
+ fi
32
+
33
+ # Fallback: search common locations
34
+ local locations=(
35
+ "/usr/local/lib/node_modules/openmux"
36
+ "/usr/lib/node_modules/openmux"
37
+ "$HOME/.npm-global/lib/node_modules/openmux"
38
+ )
39
+ for loc in "${locations[@]}"; do
40
+ if [[ -d "$loc" ]]; then
41
+ echo "$loc"
42
+ return
43
+ fi
44
+ done
45
+
46
+ echo ""
47
+ }
48
+
49
+ get_version() {
50
+ local pkg_json="$1/package.json"
51
+ if [[ -f "$pkg_json" ]]; then
52
+ grep '"version"' "$pkg_json" | head -1 | sed 's/.*"version": *"\([^"]*\)".*/\1/'
53
+ else
54
+ echo ""
55
+ fi
56
+ }
57
+
58
+ get_platform() {
59
+ local os arch
60
+ os="$(uname -s)"
61
+ arch="$(uname -m)"
62
+
63
+ case "$os" in
64
+ Darwin) os="darwin" ;;
65
+ Linux) os="linux" ;;
66
+ *) echo ""; return ;;
67
+ esac
68
+
69
+ case "$arch" in
70
+ x86_64|amd64) arch="x64" ;;
71
+ arm64|aarch64) arch="arm64" ;;
72
+ *) echo ""; return ;;
73
+ esac
74
+
75
+ echo "${os}-${arch}"
76
+ }
77
+
78
+ download_binary() {
79
+ local package_dir="$1"
80
+ local dist_dir="$package_dir/dist"
81
+ local version="v$(get_version "$package_dir")"
82
+ local platform="$(get_platform)"
83
+
84
+ if [[ -z "$version" || "$version" == "v" ]]; then
85
+ echo "Error: Could not determine openmux version" >&2
86
+ return 1
87
+ fi
88
+
89
+ if [[ -z "$platform" ]]; then
90
+ echo "Error: Unsupported platform" >&2
91
+ return 1
92
+ fi
93
+
94
+ local url="https://github.com/$REPO/releases/download/$version/openmux-$version-$platform.tar.gz"
95
+
96
+ echo "Downloading openmux $version for $platform..."
97
+ echo "From: $url"
98
+
99
+ mkdir -p "$dist_dir"
100
+ local tmp_file="$dist_dir/download.tar.gz"
101
+
102
+ # Download
103
+ if command -v curl &>/dev/null; then
104
+ curl -fsSL "$url" -o "$tmp_file" || return 1
105
+ elif command -v wget &>/dev/null; then
106
+ wget -q "$url" -O "$tmp_file" || return 1
107
+ else
108
+ echo "Error: curl or wget required" >&2
109
+ return 1
110
+ fi
111
+
112
+ # Extract
113
+ echo "Extracting..."
114
+ tar -xzf "$tmp_file" -C "$dist_dir"
115
+ rm -f "$tmp_file"
116
+
117
+ # 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
+ }
124
+
125
+ PACKAGE_DIR="$(find_package_dir)"
126
+
127
+ if [[ -z "$PACKAGE_DIR" ]]; then
128
+ echo "Error: Could not find openmux package directory" >&2
129
+ exit 1
130
+ fi
6
131
 
7
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8
- PACKAGE_DIR="$(dirname "$SCRIPT_DIR")"
9
132
  DIST_DIR="$PACKAGE_DIR/dist"
10
133
 
11
134
  # Determine library extension based on OS
@@ -15,11 +138,9 @@ case "$(uname -s)" in
15
138
  *) echo "Unsupported OS" >&2; exit 1 ;;
16
139
  esac
17
140
 
18
- # Check if binary exists
141
+ # Download binary if missing
19
142
  if [[ ! -x "$DIST_DIR/openmux-bin" ]]; then
20
- echo "Error: openmux binary not found at $DIST_DIR/openmux-bin" >&2
21
- echo "Run 'npm run build' or reinstall the package" >&2
22
- exit 1
143
+ download_binary "$PACKAGE_DIR" || exit 1
23
144
  fi
24
145
 
25
146
  # Set library path and execute
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openmux",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Terminal multiplexer with master-stack tiling layout",
5
5
  "module": "src/index.tsx",
6
6
  "type": "module",