chore(fish): Split functions into multiple files
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -13,6 +13,9 @@
|
||||
!fish/config.fish
|
||||
!fish/functions
|
||||
!fish/functions/env.fish
|
||||
!fish/functions/check_git_status.fish
|
||||
!fish/functions/check_and_source_activate.fish
|
||||
!fish/functions/check_directory_for_new_repository.fish
|
||||
!fish/completions
|
||||
!fish/completions/env.fish
|
||||
!fish/environments
|
||||
|
||||
@@ -7,6 +7,10 @@ set -g -x fish_greeting ""
|
||||
set -U os (uname)
|
||||
set -U TERMINAL "st"
|
||||
|
||||
# Keybinds
|
||||
## Unbind control + V keybind
|
||||
bind -e \cv
|
||||
|
||||
# Exports
|
||||
## zoxide
|
||||
export FZF_DEFAULT_OPTS='--height 40%'
|
||||
@@ -54,7 +58,10 @@ alias pacman="sudo pacman"
|
||||
alias upc="sudo pacman -Syu; pkill -RTMIN+8 dwmblocks"
|
||||
alias lsp="pacman -Qett | less" #--color=always
|
||||
|
||||
### Shortcut creation
|
||||
## Git update for dotfiles
|
||||
alias update="git -C ~/.config pull && git -C ~/.local pull"
|
||||
|
||||
## Shortcut creation
|
||||
alias ref="shortcuts >/dev/null; source ~/.config/shortcutrc"
|
||||
|
||||
## Lazy / Filebrowsing
|
||||
@@ -64,18 +71,18 @@ alias r="ranger"
|
||||
alias f="fzf"
|
||||
alias fn="nvim (fzf)"
|
||||
|
||||
### eza, a fork of exa, a coloured ls alternative
|
||||
## eza, a fork of exa, a coloured ls alternative
|
||||
alias ls="eza "
|
||||
alias la="eza -la"
|
||||
alias ols="/usr/bin/ls"
|
||||
alias olsc="/usr/bin/ls -hN --color=auto --group-directories-first"
|
||||
|
||||
### Set colours default for commands
|
||||
## Set colours default for commands
|
||||
alias diff="diff --color=auto"
|
||||
alias grep="grep --color=auto"
|
||||
alias ccat="highlight --out-format=ansi"
|
||||
|
||||
### Show system information
|
||||
## Show system information
|
||||
alias show="inxi -vvG && fastfetch"
|
||||
|
||||
## Development
|
||||
@@ -93,6 +100,16 @@ set -q GHCUP_INSTALL_BASE_PREFIX[1]; or set GHCUP_INSTALL_BASE_PREFIX $HOME ; se
|
||||
alias yt="yt-dlp --add-metadata -i -o '%(upload_date)s-%(title)s.%(ext)s'"
|
||||
alias yta="yt -x -f bestaudio/best"
|
||||
|
||||
# Run zoxide, onefetch and env detector on CD
|
||||
function cd -w='cd'
|
||||
z $argv || return
|
||||
check_directory_for_new_repository
|
||||
check_and_source_activate
|
||||
end
|
||||
|
||||
check_git_status $HOME/.config
|
||||
check_git_status $HOME/.local
|
||||
|
||||
# Set custom prompt
|
||||
function fish_prompt -d "Write out the prompt"
|
||||
set_color "c0241e"; printf "["
|
||||
@@ -104,55 +121,6 @@ function fish_prompt -d "Write out the prompt"
|
||||
set_color "99AAB5"; printf "\$ "
|
||||
end
|
||||
|
||||
bind -e \cv
|
||||
|
||||
# Run zoxide, onefetch and env detector on CD
|
||||
function cd -w='cd'
|
||||
z $argv || return
|
||||
check_directory_for_new_repository
|
||||
check_and_source_activate
|
||||
end
|
||||
|
||||
function check_directory_for_new_repository
|
||||
set current_repository (git rev-parse --show-toplevel 2> /dev/null)
|
||||
if [ "$current_repository" ] && \
|
||||
[ "$current_repository" != "$last_repository" ]
|
||||
if type -q onefetch
|
||||
onefetch
|
||||
end
|
||||
end
|
||||
set -gx last_repository $current_repository
|
||||
end
|
||||
|
||||
function check_and_source_activate
|
||||
if test -f (pwd)/.fish/activate.fish
|
||||
echo (set_color green)"Found .fish/activate.fish in current directory, sourcing..."(set_color normal)
|
||||
source (pwd)/.fish/activate.fish
|
||||
else if test -f (pwd)/activate.fish
|
||||
echo (set_color green)"Found activate.fish in current directory, sourcing..."(set_color normal)
|
||||
source (pwd)/activate.fish
|
||||
end
|
||||
end
|
||||
|
||||
# Check if any directory has git updates
|
||||
function check_git_status
|
||||
set target_dir $argv[1]
|
||||
if test -z "$target_dir"
|
||||
set target_dir (pwd)
|
||||
end
|
||||
|
||||
if test -d $target_dir/.git
|
||||
set git_status (git -C $target_dir status --porcelain)
|
||||
if test -n "$git_status"
|
||||
set dir_name (basename $target_dir)
|
||||
echo (set_color yellow)"[$dir_name] There are uncommitted changes or untracked files."(set_color normal)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
check_git_status $HOME/.config
|
||||
check_git_status $HOME/.local
|
||||
|
||||
# Start tmux by default
|
||||
# if status is-interactive
|
||||
# and not set -q TMUX
|
||||
|
||||
9
fish/functions/check_and_source_activate.fish
Normal file
9
fish/functions/check_and_source_activate.fish
Normal file
@@ -0,0 +1,9 @@
|
||||
function check_and_source_activate
|
||||
if test -f (pwd)/.fish/activate.fish
|
||||
echo (set_color green)"Found .fish/activate.fish in current directory, sourcing..."(set_color normal)
|
||||
source (pwd)/.fish/activate.fish
|
||||
else if test -f (pwd)/activate.fish
|
||||
echo (set_color green)"Found activate.fish in current directory, sourcing..."(set_color normal)
|
||||
source (pwd)/activate.fish
|
||||
end
|
||||
end
|
||||
10
fish/functions/check_directory_for_new_repository.fish
Normal file
10
fish/functions/check_directory_for_new_repository.fish
Normal file
@@ -0,0 +1,10 @@
|
||||
function check_directory_for_new_repository
|
||||
set current_repository (git rev-parse --show-toplevel 2> /dev/null)
|
||||
if [ "$current_repository" ] && \
|
||||
[ "$current_repository" != "$last_repository" ]
|
||||
if type -q onefetch
|
||||
onefetch
|
||||
end
|
||||
end
|
||||
set -gx last_repository $current_repository
|
||||
end
|
||||
15
fish/functions/check_git_status.fish
Normal file
15
fish/functions/check_git_status.fish
Normal file
@@ -0,0 +1,15 @@
|
||||
# Check if any directory has git updates
|
||||
function check_git_status
|
||||
set target_dir $argv[1]
|
||||
if test -z "$target_dir"
|
||||
set target_dir (pwd)
|
||||
end
|
||||
|
||||
if test -d $target_dir/.git
|
||||
set git_status (git -C $target_dir status --porcelain)
|
||||
if test -n "$git_status"
|
||||
set dir_name (basename $target_dir)
|
||||
echo (set_color yellow)"[$dir_name] There are uncommitted changes or untracked files."(set_color normal)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user