Skip to content

Commit 178b276

Browse files
committed
feat(fish): improve alias to use abbreviations
1 parent 184d150 commit 178b276

22 files changed

Lines changed: 365 additions & 285 deletions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Load order configuration for Fish shell
2+
# This file ensures proper loading sequence of functions
3+
4+
# Load critical functions first
5+
for file in $__fish_config_dir/functions/load_first/*.fish
6+
if test -f $file
7+
source $file
8+
end
9+
end
10+
11+
# Load utility functions last (after everything else is initialized)
12+
for file in $__fish_config_dir/functions/load_last/*.fish
13+
if test -f $file
14+
source $file
15+
end
16+
end
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Fish abbreviations - faster than aliases
2+
# These expand when you press space or enter
3+
4+
# Navigation abbreviations
5+
abbr -a .. 'cd ..'
6+
abbr -a ... 'cd ../..'
7+
abbr -a .3 'cd ../../..'
8+
abbr -a .4 'cd ../../../..'
9+
abbr -a .5 'cd ../../../../..'
10+
11+
# Directory operations
12+
abbr -a --position anywhere --set-cursor='%' cdl 'cd % && ls'
13+
14+
# File operations
15+
abbr -a ll 'eza -lg --color=always --icons --group-directories-first'
16+
abbr -a la 'eza -a --color=always --git-ignore --group-directories-first'
17+
abbr -a lt1 'eza -aT --color=always --git-ignore --level=1 --group-directories-first'
18+
abbr -a lt2 'eza -aT --color=always --git-ignore --level=2 --group-directories-first'
19+
abbr -a lt3 'eza -aT --color=always --git-ignore --level=3 --group-directories-first'
20+
abbr -a llg 'eza --tree --level=2 --long -g --icons --git'
21+
abbr -a l. 'eza -a | grep -E "^\."'
22+
23+
# Editor abbreviations
24+
abbr -a nv nvim
25+
abbr -a vi nvim
26+
abbr -a vim nvim
27+
abbr -a v nvim
28+
29+
# System abbreviations
30+
abbr -a cl reset
31+
abbr -a clear reset
32+
abbr -a ping 'ping -c 10'
33+
abbr -a df 'df -h'
34+
abbr -a free 'free -m'
35+
abbr -a wget 'wget -c'
36+
abbr -a hf 'history | fzf'
37+
38+
# Git abbreviations
39+
abbr -a lg lazygit
40+
abbr -a gl 'git log --oneline'
41+
abbr -a glp 'git log --pretty=format:"%C(yellow)%h%Creset - %C(green)%an%Creset, %ar : %s"'
42+
abbr -a glt 'git log --graph --oneline --all --decorate'
43+
44+
# Shell switching
45+
abbr -a tobash 'sudo chsh $USER -s /bin/bash && echo "Now log out."'
46+
abbr -a tozsh 'sudo chsh $USER -s /bin/zsh && echo "Now log out."'
47+
abbr -a tofish 'sudo chsh $USER -s /bin/fish && echo "Now log out."'
48+
49+
# Utilities
50+
abbr -a yz yazi
51+
abbr -a :q exit
52+
abbr -a day 'date +"%Y-%m-%d %A"'
53+
abbr -a wtr 'curl wttr.in'
54+
abbr -a ist 'curl -s "https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py" | python3 -'
55+
abbr -a tt 'tmux new-session -A -s'
56+
57+
# Special abbreviations with cursor positioning
58+
abbr -a --position anywhere --set-cursor='%' -- L '% | less'

roles/fish/files/conf.d/fzf.fish

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# FZF Configuration
2+
# Optimized FZF settings for better performance and usability
3+
4+
# Basic FZF options - layout=reverse makes the prompt at the top
5+
set -gx FZF_DEFAULT_OPTS "--height=65% --layout=reverse --bind ctrl-u:preview-page-up,ctrl-d:preview-page-down"
6+
7+
# Default command for file listing - uses fd for better performance
8+
set -gx FZF_DEFAULT_COMMAND "fd --hidden --strip-cwd-prefix --exclude .git"
9+
set -gx FZF_CTRL_T_COMMAND "$FZF_DEFAULT_COMMAND"
10+
11+
# Preview options for CTRL-T (file search)
12+
set -gx FZF_CTRL_T_OPTS "--preview 'bat --color=always --style=numbers --line-range=:500 {}' --preview-window=right:noborder"
13+
14+
# Preview options for ALT-C (directory search)
15+
set -gx FZF_ALT_C_OPTS "--preview 'eza --tree --icons --color=always {} | head -n 200' --preview-window=right:noborder"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Package Manager Path Configuration
2+
# Centralized path management for various package managers
3+
4+
# Bun
5+
if test -d "$HOME/.bun"
6+
set -gx BUN_INSTALL "$HOME/.bun"
7+
fish_add_path "$BUN_INSTALL/bin"
8+
end
9+
10+
# pnpm
11+
set -l pnpm_home "$HOME/.local/share/pnpm"
12+
if test -d $pnpm_home
13+
set -gx PNPM_HOME $pnpm_home
14+
fish_add_path "$PNPM_HOME"
15+
end
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
21
source "$HOME/.cargo/env.fish"

roles/fish/files/conf.d/ssh.fish

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# SSH Configuration
2+
# Automated SSH agent setup and key management
3+
4+
# Function to add SSH keys automatically
5+
function _add_ssh_keys
6+
# Array of SSH keys to load (add your keys here)
7+
set ssh_keys \
8+
"$HOME/.ssh/gh_login_shricodev" \
9+
"$HOME/.ssh/homelab-vm_key.pem"
10+
11+
for key in $ssh_keys
12+
if test -f $key
13+
ssh-add $key >/dev/null 2>&1
14+
end
15+
end
16+
end
17+
18+
# Setup SSH agent if not already running
19+
if not set -q SSH_AUTH_SOCK
20+
eval (ssh-agent -c) >/dev/null 2>&1
21+
end
22+
23+
# Add SSH keys if SSH agent is running
24+
if set -q SSH_AUTH_SOCK
25+
_add_ssh_keys
26+
end

roles/fish/files/config.fish

Lines changed: 34 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,34 @@
11
# My fish config. Not much to see here; just some pretty standard stuff.
22

3-
### ADDING TO THE PATH
4-
# First line removes the path; second line sets it. Without the first line,
5-
# your path gets massive and fish becomes very slow.
6-
set -e fish_user_paths
7-
set -U fish_user_paths $HOME/.bin $HOME/.local/bin $HOME/local/bin $HOME/.config/emacs/bin $HOME/Applications /var/lib/flatpak/exports/bin/ $HOME/go/bin $HOME/.fzf/bin $fish_user_paths
8-
9-
#Remove fish vi mode indication in the prompt
3+
fish_add_path \
4+
"$HOME/.bin" \
5+
"$HOME/.local/bin" \
6+
"$HOME/local/bin" \
7+
"$HOME/.config/emacs/bin" \
8+
"$HOME/Applications" \
9+
"/var/lib/flatpak/exports/bin" \
10+
"$HOME/go/bin" \
11+
"$HOME/.fzf/bin"
12+
13+
# Remove fish vi mode indication in the prompt
1014
function fish_mode_prompt; end
1115

12-
# init starship quickly
13-
starship init fish | source
16+
# init starship quickly (only in interactive mode)
17+
if status is-interactive
18+
starship init fish | source
19+
end
1420

15-
set fish_greeting # Suppress fish's intro message
21+
# Suppress fish's intro message
22+
set fish_greeting
1623

1724
# use the default terminal color
18-
set TERM xterm-256color # Sets the terminal type
25+
set TERM xterm-256color
1926

2027
set -gx BAT_THEME "tokyonight_night"
2128

22-
# -- layout=reverse makes the prompt at the top instead of at the bottom
23-
set -gx FZF_DEFAULT_OPTS "--height=65% --layout=reverse --bind ctrl-u:preview-page-up,ctrl-d:preview-page-down"
24-
25-
# Use this command to list files in the fzf window when simply run the 'fzf' command.
26-
# Make sure to use the CTRL-T and ALT-C to its fullest.
27-
set -gx FZF_DEFAULT_COMMAND "fd --hidden --strip-cwd-prefix --exclude .git"
28-
set -gx FZF_CTRL_T_COMMAND "$FZF_DEFAULT_COMMAND"
29-
30-
set -gx FZF_CTRL_T_OPTS "--preview 'bat --color=always --style=numbers --line-range=:500 {}' --preview-window=right:noborder"
31-
set -gx FZF_ALT_C_OPTS "--preview 'eza --tree --icons --color=always {} | head -n 200' --preview-window=right:noborder"
32-
3329
fish_config theme choose "Rosé Pine"
3430

35-
#set up NEOVIM as a default editor.
31+
# set up NEOVIM as a default editor.
3632
set -gx EDITOR nvim
3733
set -gx GIT_EDITOR nvim
3834

@@ -42,140 +38,37 @@ set -g fish_cursor_insert block
4238
set -g fish_cursor_replace block
4339
set -g fish_cursor_visual block
4440

45-
#Setup SSH running. (mostly for git push)
46-
if not set -q SSH_AUTH_SOCK
47-
# Redirecting the error or the output to the /dev/null
48-
eval (ssh-agent -c) > /dev/null 2>&1
49-
end
50-
51-
# If we are in this line, the ssh-agent should always be set up and running.
52-
# Add our private key to the ssh-agent
53-
# Redirecting the error or the output to the /dev/null
54-
ssh-add ~/.ssh/gh_login_shricodev > /dev/null 2>&1
55-
56-
#This is the private key for my homelab vm on azure
57-
# ssh-add ~/.ssh/homelab-vm_key.pem > /dev/null 2>&1
58-
5941
# Open tmux as default when the shell starts
60-
# Attach to or create the base session
61-
if not set -q TMUX
42+
# Only attach if we're in an interactive session to avoid breaking scripts
43+
if not set -q TMUX; and status is-interactive
6244
set -g TMUX tmux new-session -d -s mainline
6345
eval $TMUX
6446
tmux attach-session -d -t mainline
6547
end
6648

67-
68-
### ALIASES ###
69-
# navigation
70-
alias ..='cd ..'
71-
alias ...='cd ../..'
72-
alias .3='cd ../../..'
73-
alias .4='cd ../../../..'
74-
alias .5='cd ../../../../..'
75-
76-
alias ping="ping -c 10"
77-
78-
alias cat='bat --style=plain --paging=never'
79-
80-
alias nv='nvim'
81-
alias vi='nvim'
82-
alias vim='nvim'
83-
alias v='nvim'
84-
85-
alias cl='reset'
86-
# Make the `clear` command work as Ctrl - l as by default `clear` command clears
87-
# the screen completely
88-
alias clear='reset'
89-
alias clearraw='command clear'
90-
91-
# Changing "ls" to "eza"
92-
alias ls='eza -alg --color=always --icons --group-directories-first' # my preferred listing
93-
#alias to use when you need to access the raw ls command
94-
alias lsraw='command ls'
95-
96-
alias ll='eza -lg --color=always --icons --group-directories-first'
97-
98-
alias la='eza -a --color=always --git-ignore --group-directories-first' # all files and dirs
99-
alias lt1='eza -aT --color=always --git-ignore --level=1 --group-directories-first'
100-
alias lt2='eza -aT --color=always --git-ignore --level=2 --group-directories-first'
101-
alias lt3='eza -aT --color=always --git-ignore --level=3 --group-directories-first'
102-
103-
alias llg="eza --tree --level=2 --long -g --icons --git"
104-
105-
# Show only the dotfiles
106-
alias l.='eza -a | grep -E "^\."'
107-
108-
# Colorize grep output (good for log files)
109-
alias grep='grep --color=auto'
110-
111-
# adding flags
112-
alias df='df -h' # human-readable sizes
113-
alias free='free -m' # show sizes in MB
114-
115-
# Fuzzily find history
116-
alias hf='history | fzf'
117-
118-
# Continue from where the download got interrupted if it happens.
119-
# Without -c flag, wget will start downloading the file from scratch if the operation fails due to some
120-
# network issues.
121-
alias wget="wget -c"
122-
123-
alias lg="lazygit"
124-
125-
# switch between shells
126-
# The shell path is hard coded for now since adding $(which <shell>) would result in warning in the terminal
127-
# if the shell is not installed.
128-
alias tobash="sudo chsh $USER -s /bin/bash && echo 'Now log out.'"
129-
alias tozsh="sudo chsh $USER -s /bin/zsh && echo 'Now log out.'"
130-
alias tofish="sudo chsh $USER -s /bin/fish && echo 'Now log out.'"
131-
132-
# Safety nets
133-
# do not delete / or prompt if deleting more than 3 files at a time
49+
# keep as alias since it's the base ls command replacement
50+
alias ls='eza -alg --color=always --icons --group-directories-first'
13451
alias rm='rm -I --preserve-root'
135-
136-
# confirmation
137-
alias mv='mv -i'
13852
alias cp='cp -i'
53+
alias mv='mv -i'
13954
alias ln='ln -i'
140-
141-
# Parenting changing perms on /
14255
alias chown='chown --preserve-root'
14356
alias chmod='chmod --preserve-root'
14457
alias chgrp='chgrp --preserve-root'
14558

146-
# git aliases
147-
alias gl='git log --oneline'
148-
alias glp='git log --pretty=format:"%C(yellow)%h%Creset - %C(green)%an%Creset, %ar : %s"'
149-
alias glt='git log --graph --oneline --all --decorate'
150-
151-
# Yazi file manager
152-
alias yz='yazi'
153-
154-
alias :q="exit"
155-
156-
alias day="date +'%Y-%m-%d %A'"
157-
158-
# Weather in current location
159-
alias wtr="curl wttr.in"
160-
161-
# Do the internet speed test
162-
alias ist="curl -s 'https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py' | python3 -"
59+
# some raw aliases
60+
alias lsraw='command ls'
61+
alias clearraw='command clear'
16362

164-
abbr -a --position anywhere --set-cursor='%' -- L '% | less'
63+
# colorize grep output (good for log files) - keep as global setting
64+
alias grep='grep --color=auto'
16565

166-
# bun
167-
set --export BUN_INSTALL "$HOME/.bun"
168-
set --export PATH $BUN_INSTALL/bin $PATH
66+
bind \cd delete-char # don't exit on accidental Ctrl-D
67+
bind \cd\cd\cd delete-or-exit # exit on the third one
16968

170-
# pnpm
171-
set -gx PNPM_HOME "/home/shricodev/.local/share/pnpm"
172-
if not string match -q -- $PNPM_HOME $PATH
173-
set -gx PATH "$PNPM_HOME" $PATH
69+
# initialize zoxide only in interactive mode
70+
if status is-interactive
71+
zoxide init fish | source
17472
end
17573

176-
bind \cd delete-char # Don't exit on accidental Ctrl-D
177-
bind \cd\cd\cd delete-or-exit # Exit on the third one
178-
179-
zoxide init fish | source
180-
18174
# toilet "shricodev" -F border -F rainbow -f pagga

roles/fish/files/fish_variables

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ SETUVAR fish_pager_color_selected_background:\x2d\x2dreverse
5252
SETUVAR fish_pager_color_selected_completion:\x1d
5353
SETUVAR fish_pager_color_selected_description:\x1d
5454
SETUVAR fish_pager_color_selected_prefix:\x1d
55-
SETUVAR fish_user_paths:/home/shricodev/\x2ebin\x1e/home/shricodev/\x2elocal/bin\x1e/home/shricodev/local/bin\x1e/home/shricodev/\x2econfig/emacs/bin\x1e/home/shricodev/Applications\x1e/var/lib/flatpak/exports/bin/\x1e/home/shricodev/go/bin\x1e/home/shricodev/\x2efzf/bin
55+
SETUVAR fish_user_paths:/var/lib/flatpak/exports/bin\x1e/home/shricodev/\x2ebin\x1e/home/shricodev/\x2elocal/bin\x1e/home/shricodev/local/bin\x1e/home/shricodev/\x2econfig/emacs/bin\x1e/home/shricodev/Applications\x1e/var/lib/flatpak/exports/bin/\x1e/home/shricodev/go/bin\x1e/home/shricodev/\x2efzf/bin

roles/fish/files/functions/backup.fish

Lines changed: 0 additions & 10 deletions
This file was deleted.

roles/fish/files/functions/cdl.fish

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)