pub const ZSH_WRAPPER: &str = r#"# f shell function - enables `f N` to cd into directories
# Installed by: f install
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
# NOTE: zsh arrays are 1-indexed — first element is args[1], second is args[2].
if [[ "${args[1]}" =~ ^[0-9]+$ ]]; then
local num="${args[1]}"
local action="${args[2]:-}"
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 [[ -z "$target_path" ]]; then
return
elif [[ -d "$target_path" ]]; then
cd "$target_path"
else
# File: open in editor. Prefer $EDITOR; fall back to the first
# available editor so `f N` never dies with "command not
# found" on installs that lack micro.
local editor="${EDITOR:-$(command -v micro || command -v nano || command -v vim || command -v vi)}"
"${editor:-vi}" "$target_path"
fi
fi
else
# Normal f invocation
command f "$@"
fi
}
"#;
pub const BASH_WRAPPER: &str = r#"# f shell function - enables `f N` to cd into directories
# Installed by: f install
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
# bash arrays are 0-indexed.
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 [[ -z "$target_path" ]]; then
return
elif [[ -d "$target_path" ]]; then
cd "$target_path"
else
# File: open in editor. Prefer $EDITOR; fall back to the first
# available editor so `f N` never dies with "command not
# found" on installs that lack micro.
local editor="${EDITOR:-$(command -v micro || command -v nano || command -v vim || command -v vi)}"
"${editor:-vi}" "$target_path"
fi
fi
else
# Normal f invocation
command f "$@"
fi
}
"#;
pub const FISH_WRAPPER: &str = r#"# f shell function - enables `f N` to cd into directories
# Installed by: f install
function f --description "Folder Auto Banner with numeric navigation"
set -l edit_mode false
set -l run_mode false
set -l remaining_args
for arg in $argv
switch $arg
case --edit -e
set edit_mode true
case --run -x
set run_mode true
case '*'
set -a remaining_args $arg
end
end
if test (count $remaining_args) -gt 0; and string match -qr '^[0-9]+$' -- $remaining_args[1]
set -l num $remaining_args[1]
set -l action $remaining_args[2]
if test -n "$action"
command f banner "$num" "$action"
else if test "$edit_mode" = true
command f banner --edit "$num"
else if test "$run_mode" = true
command f banner --run "$num"
else
set -l target_path (command f banner "$num")
if test -z "$target_path"
return
else if test -d "$target_path"
cd "$target_path"
else
set -l editor $EDITOR
if test -z "$editor"
if type -q micro
set editor micro
else if type -q nano
set editor nano
else if type -q vim
set editor vim
else
set editor vi
end
end
$editor "$target_path"
end
end
else
command f $argv
end
end
"#;