FIX:tested

swadhinbiswas committed 8 months ago
16dca6a
1 parent 20692aa
commit 16dca6a
4 files changed
+225 -3
▼.github/FUNDING.yml
+1-1
1
-github: rampxty
1
+github: Catgle
2
2
▼.github/workflows/test.yml
+16-1
7
7
branches: [ main ]
8
8
9
9
jobs:
10
- test:
10
+ rust-test:
11
+ name: Rust (v5.0.x)
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ - name: Install Rust
16
+ uses: dtolnay/rust-toolchain@stable
17
+ - name: Build
18
+ run: cargo build --verbose
19
+ - name: Run help
20
+ run: cargo run -- --help
21
+ - name: Run version
22
+ run: cargo run -- --version
23
+
24
+ legacy-test:
25
+ name: Legacy Bash/Python (v4.x)
11
26
runs-on: ubuntu-latest
12
27
strategy:
13
28
matrix:
14
29
▼install.sh
+207-0
1
+#!/usr/bin/env bash
2
+
3
+set -euo pipefail
4
+
5
+SCRIPT_NAME="lsf"
6
+VERSION="1"
7
+
8
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
9
+
10
+usage() {
11
+ cat <<EOF
12
+Usage: $0 [--user | --system] [--replace-ls] [--force] [--no-font-check]
13
+
14
+Options:
15
+ --user Install to user local bin (~/.local/bin). Default when not root.
16
+ --system Install system-wide to /usr/local/bin. Requires sudo or root.
17
+ --replace-ls Replace system 'ls' command by creating a wrapper at /usr/local/bin/ls (backups created).
18
+ --force Overwrite existing files without prompt.
19
+ --no-font-check Skip checking for Nerd Fonts.
20
+ -h, --help Show this help message.
21
+
22
+This installer will copy the bundled 'lsf' script and 'column.py' helper into the chosen bin directory
23
+and create a config directory at ~/.config/lsf (if not present).
24
+EOF
25
+}
26
+
27
+INSTALL_SYSTEM=false
28
+REPLACE_LS=false
29
+FORCE=false
30
+FONT_CHECK=true
31
+
32
+while [ "$#" -gt 0 ]; do
33
+ case "$1" in
34
+ --user)
35
+ INSTALL_SYSTEM=false
36
+ shift
37
+ ;;
38
+ --system)
39
+ INSTALL_SYSTEM=true
40
+ shift
41
+ ;;
42
+ --replace-ls)
43
+ REPLACE_LS=true
44
+ shift
45
+ ;;
46
+ --force)
47
+ FORCE=true
48
+ shift
49
+ ;;
50
+ --no-font-check)
51
+ FONT_CHECK=false
52
+ shift
53
+ ;;
54
+ -h|--help)
55
+ usage
56
+ exit 0
57
+ ;;
58
+ *)
59
+ echo "Unknown arg: $1"
60
+ usage
61
+ exit 2
62
+ ;;
63
+ esac
64
+done
65
+
66
+# Decide default install dir
67
+if [ "$INSTALL_SYSTEM" = true ] || [ "$(id -u)" -eq 0 ]; then
68
+ BIN_DIR="/usr/local/bin"
69
+else
70
+ BIN_DIR="$HOME/.local/bin"
71
+fi
72
+
73
+CONFIG_DIR="$HOME/.config/lsf"
74
+CONFIG_FILE="$CONFIG_DIR/lsf.conf"
75
+
76
+# Check for Rust version first
77
+RUST_BINARY="$SCRIPT_DIR/target/release/lsf"
78
+USE_RUST=false
79
+
80
+if [ -f "$RUST_BINARY" ]; then
81
+ USE_RUST=true
82
+elif command -v cargo >/dev/null 2>&1; then
83
+ echo "Rust binary not found. Attempting to build with cargo..."
84
+ if cargo build --release; then
85
+ USE_RUST=true
86
+ else
87
+ echo "Warning: cargo build failed. Falling back to Bash version." >&2
88
+ fi
89
+fi
90
+
91
+if [ "$USE_RUST" = true ]; then
92
+ echo "Using Rust version (v5.0.x)"
93
+ LSF_SOURCE="$RUST_BINARY"
94
+else
95
+ echo "Using legacy Bash version (v4.x)"
96
+ if [ ! -f "$SCRIPT_DIR/lsf" ]; then
97
+ echo "Error: unable to locate 'lsf' next to install.sh. Please run this installer from an ls-f checkout." >&2
98
+ exit 1
99
+ fi
100
+ LSF_SOURCE="$SCRIPT_DIR/lsf"
101
+fi
102
+
103
+echo "Installing to: $BIN_DIR"
104
+
105
+if [ "$FONT_CHECK" = true ]; then
106
+ if ! command -v fc-list >/dev/null 2>&1; then
107
+ echo "Warning: 'fc-list' not available; skipping Nerd Font check. Use --no-font-check to suppress this check." >&2
108
+ else
109
+ if ! fc-list | grep -i "Nerd Font" >/dev/null 2>&1; then
110
+ echo "Warning: Nerd Fonts not detected. Icons may not render correctly." >&2
111
+ echo "Visit https://www.nerdfonts.com/ for installation instructions." >&2
112
+ fi
113
+ fi
114
+fi
115
+
116
+# Create config dir and default config
117
+mkdir -p "$CONFIG_DIR"
118
+if [ ! -f "$CONFIG_FILE" ]; then
119
+ cat > "$CONFIG_FILE" <<'EOL'
120
+# Config file for lsf
121
+# You can override the default icons and colors here.
122
+# Example:
123
+# ICONS["dir"]=""
124
+# COLORS["dir"]="\e[31m"
125
+EOL
126
+ echo "Created default config at $CONFIG_FILE"
127
+fi
128
+
129
+# Ensure bin dir exists
130
+mkdir -p "$BIN_DIR"
131
+
132
+install_file() {
133
+ local src="$1"
134
+ local dest_name="$(basename "$src")"
135
+ local dest="$BIN_DIR/$dest_name"
136
+
137
+ if [ -e "$dest" ] && [ "$FORCE" = false ]; then
138
+ # If running in non-interactive mode (CI), don't ask
139
+ if [ -t 0 ]; then
140
+ read -r -p "$dest exists. Overwrite? [y/N] " ans || ans=n
141
+ if [[ ! "$ans" =~ ^[Yy]$ ]]; then
142
+ echo "Skipping $dest"
143
+ return
144
+ fi
145
+ else
146
+ echo "Overwriting $dest (non-interactive mode)"
147
+ fi
148
+ fi
149
+ cp "$src" "$dest"
150
+ chmod +x "$dest"
151
+ echo "Installed $dest"
152
+}
153
+
154
+# Install main script/binary
155
+install_file "$LSF_SOURCE"
156
+
157
+# Install helper (column.py) only for legacy version
158
+if [ "$USE_RUST" = false ] && [ -f "$SCRIPT_DIR/column.py" ]; then
159
+ install_file "$SCRIPT_DIR/column.py"
160
+fi
161
+
162
+if [ "$REPLACE_LS" = true ]; then
163
+ # Only allow replace-ls when installing system-wide
164
+ if [ "$BIN_DIR" != "/usr/local/bin" ]; then
165
+ echo "--replace-ls requires system installation (run with --system or sudo)." >&2
166
+ else
167
+ LS_WRAPPER="/usr/local/bin/ls"
168
+ if [ -e "$LS_WRAPPER" ] && [ "$FORCE" = false ]; then
169
+ read -r -p "$LS_WRAPPER exists. Backup and replace it? [y/N] " ans || ans=n
170
+ if [[ ! "$ans" =~ ^[Yy]$ ]]; then
171
+ echo "Skipping replacement of ls."
172
+ else
173
+ mv "$LS_WRAPPER" "$LS_WRAPPER.bak.$(date +%s)"
174
+ fi
175
+ fi
176
+
177
+ cat > "$LS_WRAPPER" <<'EOF'
178
+#!/usr/bin/env bash
179
+# Wrapper to prefer lsf; falls back to original ls if needed
180
+if command -v lsf >/dev/null 2>&1; then
181
+ lsf "$@"
182
+else
183
+ /bin/ls "$@"
184
+fi
185
+EOF
186
+ chmod +x "$LS_WRAPPER"
187
+ echo "Installed ls wrapper at $LS_WRAPPER (original backed up if present)."
188
+ fi
189
+fi
190
+
191
+echo "Installation complete."
192
+if [[ ":$PATH:" != *":$BIN_DIR:"* ]]; then
193
+ echo "Note: $BIN_DIR is not in your PATH. Add it to be able to run 'lsf' without a full path." >&2
194
+fi
195
+echo "To use lsf as your default 'ls', add the following to your shell rc (e.g. ~/.bashrc or ~/.zshrc):"
196
+echo " alias ls='lsf'"
197
+
198
+if [ -f "$SCRIPT_DIR/config/lsf_alias_setup.sh" ]; then
199
+ echo "If you want me to set the alias automatically, run:"
200
+ echo " source $SCRIPT_DIR/config/lsf_alias_setup.sh"
201
+fi
202
+
203
+echo "Verify the installation with:"
204
+echo " lsf --version"
205
+echo " lsf -x"
206
+
207
+exit 0
0
208
▼lsf
+1-1
1
1
#!/usr/bin/env bash
2
2
3
-VERSION="4.5.0"
3
+VERSION="4.5.1"
4
4
CONFIG_DIR="$HOME/.config/lsf"
5
5
CONFIG_FILE="$CONFIG_DIR/lsf.conf"
6
6
7
7