diff --git a/README.md b/README.md index 2eb7ccc..afbdb4d 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ This config layers on top of the CachyOS base Fish configuration and adds: │ ├── fzf.fish # FZF key binding initialization │ ├── tailscale.fish # Tailscale CLI completions │ ├── theme.fish # Theme syntax highlighting colors +│ ├── tricks.fish # PATH additions, bang-bang helpers, history/backup utilities │ ├── wakatime.fish # WakaTime shell hook │ └── zoxide.fish # Zoxide z/zi aliases ├── functions/ # Custom functions (one per file) @@ -184,6 +185,7 @@ These functions wrap modern alternatives with graceful fallbacks to standard too | `ssh` | `ssh` | `kitten ssh` when inside Kitty | | `du` | `du` | `duf` (disks) / `dust` (directories) — auto-detected by argument | | `mkdir` | `mkdir` | Always passes `-p` in interactive mode | +| `copy` | `cp` | Strips trailing `/` from a source directory before `cp -r`; falls through to `cp` for all other cases | #### `du` — Smart Disk Usage @@ -344,6 +346,7 @@ Install method priority: **git+cargo source build** (fish) → **cargo** (other | `ffetch` | Run fastfetch with `~/.fastfetch.jsonc` if present | | `cffetch` | Clear screen then run fastfetch | | `hist` | FZF history search — selected command is placed in the prompt and copied to clipboard | +| `history` | Built-in `history` override — prepends `YYYY-MM-DD HH:MM:SS` timestamps to every entry | | `qr ` | Generate a terminal QR code | ### Miscellaneous @@ -355,6 +358,7 @@ Install method priority: **git+cargo source build** (fish) → **cargo** (other | `scrub` | Recursively purge OS/editor/compiler garbage from CWD; `-a` aggressive mode adds logs, `node_modules`, IDE dirs; `-d` dry-run preview; requires `fd` | | `antigravity` | Wrapper for `agy` (antigravity-cli) that suppresses a noisy warning | | `antigravity-ide` | Wrapper for `antigravity-ide` binary that suppresses a noisy warning | +| `backup ` | Copy `` to `.bak` | | `bash` | Drop into bash (raw Fish session via `rawfish`) | --- diff --git a/conf.d/tricks.fish b/conf.d/tricks.fish new file mode 100644 index 0000000..dd89032 --- /dev/null +++ b/conf.d/tricks.fish @@ -0,0 +1,67 @@ +# Copyright (C) 2026 Rootiest +# SPDX-License-Identifier: AGPL-3.0-or-later + +# ────── Borrowed and modified from CachyOS config ───────── +# ╭──────────────────────────────────────────────────────────╮ +# │ Provides PATH additions, bang-bang helpers, │ +# │ and history/backup utilities │ +# ╰──────────────────────────────────────────────────────────╯ +## Environment setup +# Apply .profile: use this to put fish compatible .profile stuff in +if test -f ~/.fish_profile + source ~/.fish_profile +end + +# Add ~/.local/bin to PATH +if test -d ~/.local/bin + if not contains -- ~/.local/bin $PATH + set -p PATH ~/.local/bin + end +end + +# Add depot_tools to PATH +if test -d ~/Applications/depot_tools + if not contains -- ~/Applications/depot_tools $PATH + set -p PATH ~/Applications/depot_tools + end +end + +## Functions +# Functions needed for !! and !$ https://github.com/oh-my-fish/plugin-bang-bang +function __history_previous_command + switch (commandline -t) + case "!" + commandline -t $history[1] + commandline -f repaint + case "*" + commandline -i ! + end +end + +function __history_previous_command_arguments + switch (commandline -t) + case "!" + commandline -t "" + commandline -f history-token-search-backward + case "*" + commandline -i '$' + end +end + +if [ "$fish_key_bindings" = fish_vi_key_bindings ] + + bind -Minsert ! __history_previous_command + bind -Minsert '$' __history_previous_command_arguments +else + bind ! __history_previous_command + bind '$' __history_previous_command_arguments +end + +# Fish command history +function history + builtin history --show-time='%F %T ' +end + +function backup --argument filename + cp $filename $filename.bak +end diff --git a/config.fish b/config.fish index 2626333..7a32a30 100644 --- a/config.fish +++ b/config.fish @@ -14,6 +14,10 @@ if test -f /usr/share/cachyos-fish-config/cachyos-config.fish functions --erase $_fname source "$__fish_config_dir/functions/$_fname.fish" end + # CachyOS defines a broken copy command. + # Override it with our working function. + test -f "$__fish_config_dir/functions/copy.fish" + and source "$__fish_config_dir/functions/copy.fish" end set --erase _fname @@ -122,15 +126,13 @@ if status is-interactive fzf --fish | source else test -f "$__fish_config_dir/integrations/fzf.fish" - and source "$__fish_config_dir/integrations/fzf.fish" + and source "$__fish_config_dir/integrations/fzf.fish" end else # conf.d/fzf.fish is managed by Fisher and may be restored on fisher # update, so this is the reliable place to strip its bindings when # fzf is not installed. - if functions -q _fzf_uninstall_bindings - _fzf_uninstall_bindings - end + functions -q _fzf_uninstall_bindings; and _fzf_uninstall_bindings end # ──────────────────────────────── DirENV ──────────────────────────────── @@ -139,9 +141,7 @@ if status is-interactive # # The Auto-Venv script above will ignore directories with a # .envrc file (direnv configuration) to prevent conflicts. - if type -q direnv - direnv hook fish | source - end + type -q direnv; and direnv hook fish | source # Helps ensure that Claude Code's terminal output is clean and doesn't have flickering issues. set -gx CLAUDE_CODE_NO_FLICKER 1 @@ -150,11 +150,7 @@ if status is-interactive # Initializes the Starship prompt, which provides a highly customizable and informative command prompt. # This is wrapped in a check to ensure that it only runs if Starship is installed, # preventing errors if it's not available. - if type -q starship - # STARSHIP_START - starship init fish | source - # STARSHIP_END - end + type -q starship; and starship init fish | source # ╭────────────────────────────── OVERRIDES ─────────────────────────────╮ # | Run these last so they can override any previous settings. | @@ -169,9 +165,7 @@ if status is-interactive # committed to version control. # This allows you to keep things like API keys, database credentials, # and other secrets out of your main config files and safely ignored by git. - if test -f "$dot_fish/secrets.fish" - source "$dot_fish/secrets.fish" - end + test -f "$dot_fish/secrets.fish"; and source "$dot_fish/secrets.fish" # ─────────────────────── Source machine-local config ──────────────────── # Sources a local.fish file if it exists, which can be used for machine-specific @@ -179,9 +173,7 @@ if status is-interactive # This allows you to have different settings on different machines without affecting # your main config or secrets files. For example, you might want different PATH additions, # aliases, or environment variables on your work laptop vs. your home desktop. - if test -f "$dot_fish/local.fish" - source "$dot_fish/local.fish" - end + test -f "$dot_fish/local.fish"; and source "$dot_fish/local.fish" # ╭──────────────────────────── END OVERRIDES ──────────────────────────╮ # | End of override section. | # ╰──────────────────────────── END OVERRIDES ──────────────────────────╯ diff --git a/functions/copy.fish b/functions/copy.fish new file mode 100644 index 0000000..0ca43c0 --- /dev/null +++ b/functions/copy.fish @@ -0,0 +1,14 @@ +# Copyright (C) 2026 Rootiest +# SPDX-License-Identifier: AGPL-3.0-or-later + +function copy + set count (count $argv) + if test "$count" = 2; and test -d "$argv[1]" + # 'string trim' is built straight into Fish and works everywhere + set from (string trim --right --chars=/ $argv[1]) + set to (echo $argv[2]) + command cp -r $from $to + else + command cp $argv + end +end