1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# f shell function - enables `f N` to cd into directories
# Add this to your .bashrc: source /path/to/fab-shell.bash
f() {
# Check for --edit/-e and --run/-x flags
local edit_mode=false
local run_mode=false
local args=("$@")
# Parse flags
local new_args=()
for arg in "${args[@]}"; do
if [[ "$arg" == "--edit" || "$arg" == "-e" ]]; then
edit_mode=true
elif [[ "$arg" == "--run" || "$arg" == "-x" ]]; then
run_mode=true
else
new_args+=("$arg")
fi
done
args=("${new_args[@]}")
# Check if first argument is a number
if [[ "${args[0]}" =~ ^[0-9]+$ ]]; then
local num="${args[0]}"
local action="${args[1]:-}"
if [[ -n "$action" ]]; then
# f N ACTION — open item N with ACTION (e.g., f 4 krita, f 4 cat)
command f banner "$num" "$action"
elif [[ "$edit_mode" == true ]]; then
# f N -e — force open in editor
command f banner --edit "$num"
elif [[ "$run_mode" == true ]]; then
# f N -x — force run the file directly
command f banner --run "$num"
else
# f N — default: cd for dirs, editor for files
local target_path
target_path=$(command f banner "$num")
if [[ -n "$target_path" ]]; then
cd "$target_path"
fi
# If target_path is empty, binary already handled the file (opened editor)
fi
else
# Normal f invocation
command f "$@"
fi
}