367 lines
11 KiB
Fish
Executable File
367 lines
11 KiB
Fish
Executable File
#
|
|
# In ~/.config/fish/configs/alias_useful.fish
|
|
#
|
|
|
|
alias mount_all='sudo $HOME/.config/fish/scripts/mount.sh'
|
|
|
|
################ COMMON ALIASES ################################################
|
|
|
|
alias remount='sudo mount -a'
|
|
alias mount_config='sudo nano /etc/fstab'
|
|
alias own='sudo chown -R "$USER":"$USER"'
|
|
alias right='sudo chmod -R 755'
|
|
function reload
|
|
if command -q omf
|
|
omf reload
|
|
else
|
|
clear
|
|
exec fish
|
|
end
|
|
end
|
|
alias fish_config='nano $HOME/.config/fish/config.fish'
|
|
alias ip='ip -color'
|
|
alias psmem='ps auxf | sort -nr -k 4'
|
|
alias psmem10='ps auxf | sort -nr -k 4 | head -10'
|
|
alias jctl='journalctl -p 3 -xb'
|
|
alias ...='cd ../..'
|
|
alias ....='cd ../../..'
|
|
alias .....='cd ../../../..'
|
|
alias ......='cd ../../../../..'
|
|
alias dir='dir --color=auto'
|
|
alias vdir='vdir --color=auto'
|
|
alias tarnow='tar -acf'
|
|
alias untar='tar -zxvf'
|
|
|
|
################ HELPERS ######################################################
|
|
|
|
function help_pdf
|
|
echo "Best Tool to combine pdf: PDF Arranger"
|
|
echo "Best Tool for OCR: OCRMYPDF but you need to install the tesseracts for your languages"
|
|
echo "Best Tool to write in PDFs: XOURNAL++"
|
|
end
|
|
|
|
if test -e /usr/bin/rsync
|
|
function rcp
|
|
if test (count $argv) -lt 2
|
|
echo "Usage: rcp SOURCE... DESTINATION"
|
|
return 1
|
|
end
|
|
rsync -avh --progress $argv
|
|
end
|
|
|
|
function rmv
|
|
if test (count $argv) -lt 2
|
|
echo "Usage: rmv SOURCE... DESTINATION"
|
|
return 1
|
|
end
|
|
rsync -avh --progress --remove-source-files $argv
|
|
end
|
|
else
|
|
function rcp
|
|
echo "'rsync' is not installed. Install it via your package manager."
|
|
end
|
|
function rmv
|
|
echo "'rsync' is not installed. Install it via your package manager."
|
|
end
|
|
end
|
|
|
|
if test -e /usr/bin/nano
|
|
function nanorm
|
|
if test (count $argv) -lt 1
|
|
echo "Usage: nanorm {FILE}"
|
|
return 1
|
|
end
|
|
nano $argv[1]
|
|
end
|
|
else
|
|
function nanorm
|
|
echo "'nano' is not installed. Install it via your package manager."
|
|
end
|
|
end
|
|
|
|
function source --description "Source files with auto-detection (replaces builtin source)"
|
|
# --- 0. Handle standard input piping (Fixes background script sourcing) ---
|
|
if not isatty stdin
|
|
builtin source $argv
|
|
return
|
|
end
|
|
|
|
# --- 1. Handle Flags First ---
|
|
if test (count $argv) -gt 0; and string match -q -- "--*" $argv[1]
|
|
builtin source $argv
|
|
return
|
|
end
|
|
|
|
# --- 2. Check: Is a file/argument given? ---
|
|
if test (count $argv) -gt 0
|
|
set file $argv[1]
|
|
set -e argv[1]
|
|
|
|
# Check if the explicit path actually exists as a file
|
|
if not test -f "$file"
|
|
echo "source: No such file: '$file'" >&2
|
|
return 1
|
|
end
|
|
|
|
# Logic: Is it .fish?
|
|
if string match -q "*.fish" -- $file
|
|
builtin source $file $argv
|
|
return
|
|
# Logic: Is it .bash?
|
|
else if string match -q "*.bash" -- $file or string match -q "*.sh" -- $file
|
|
if command -q bass
|
|
bass source $file $argv
|
|
return
|
|
else
|
|
echo "source: 'bass' is not installed. Install it to source bash files." >&2
|
|
return 1
|
|
end
|
|
# Logic: Else (unknown file type)
|
|
else
|
|
echo "source: Unknown file extension for '$file'. Please specify a .fish or .bash file." >&2
|
|
return 1
|
|
end
|
|
|
|
# --- 3. No file given: Check for local venv directories ---
|
|
else
|
|
# Target directories to check in order of preference
|
|
set venv_dirs .venv venv
|
|
|
|
for dir in $venv_dirs
|
|
if test -d "$dir"
|
|
# Check for .fish activator first
|
|
if test -f "$dir/bin/activate.fish"
|
|
builtin source "$dir/bin/activate.fish"
|
|
return
|
|
|
|
# Check for .bash activator second
|
|
else if test -f "$dir/bin/activate" or test -f "$dir/bin/activate.bash"
|
|
# Resolve which bash file exists
|
|
set bash_act "$dir/bin/activate"
|
|
if test -f "$dir/bin/activate.bash"
|
|
set bash_act "$dir/bin/activate.bash"
|
|
end
|
|
|
|
if command -q bass
|
|
bass source $bash_act
|
|
return
|
|
else
|
|
echo "source: Found bash virtual env in '$dir', but 'bass' is not installed." >&2
|
|
return 1
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
# Logic: Else error (No venv found and no args provided)
|
|
echo "source: No file specified and no local venv or .venv directory found." >&2
|
|
return 1
|
|
end
|
|
end
|
|
|
|
################ TERMINAL-SPECIFIC ############################################
|
|
|
|
if test "$TERM" = "xterm-kitty"
|
|
alias icat='kitty +kitten icat'
|
|
end
|
|
|
|
################ PYTHON #######################################################
|
|
|
|
if test -e /usr/bin/python3
|
|
alias python='python3'
|
|
alias py='python3'
|
|
end
|
|
|
|
if test -e /usr/bin/python3
|
|
function mkvenv
|
|
if not python3 -c "import venv" ^/dev/null
|
|
echo "Python3 'venv' module is not available. Install python3-venv via your package manager."
|
|
return 1
|
|
end
|
|
if test (count $argv) -lt 1
|
|
echo "Usage: mkvenv {folder name}"
|
|
return 1
|
|
end
|
|
python3 -m venv $argv[1]
|
|
if test -f $argv[1]/bin/activate.fish
|
|
source $argv[1]/bin/activate.fish
|
|
else
|
|
echo "Error: Could not find activate.fish in $argv[1]/bin/"
|
|
return 1
|
|
end
|
|
end
|
|
else
|
|
function mkvenv
|
|
echo "Python3 is not installed. Please install Python3 to use mkvenv."
|
|
end
|
|
end
|
|
|
|
if test -e /usr/bin/python3
|
|
function src
|
|
if not test -d .venv
|
|
echo "Cannot activate: .venv directory does not exist."
|
|
return 1
|
|
end
|
|
if not test -d .venv/bin
|
|
echo "Cannot activate: .venv/bin directory does not exist."
|
|
return 1
|
|
end
|
|
if test -f .venv/bin/activate.fish
|
|
source .venv/bin/activate.fish
|
|
return 0
|
|
end
|
|
if test -f .venv/bin/activate.bash
|
|
if test -e /usr/bin/bass
|
|
bass source .venv/bin/activate.bash
|
|
return 0
|
|
else
|
|
echo "'bass' is not installed. Install it via your package manager to source bash scripts."
|
|
return 1
|
|
end
|
|
end
|
|
echo "No usable activation script found in .venv/bin/"
|
|
return 1
|
|
end
|
|
else
|
|
function src
|
|
echo "Python3 is not installed. Please install Python3 to use src."
|
|
end
|
|
end
|
|
|
|
################ OLLAMA ######################################################
|
|
|
|
if test -e /usr/bin/ollama
|
|
alias llama_start='ollama serve'
|
|
alias llama3='ollama run llama3'
|
|
end
|
|
|
|
################ EZA ##########################################################
|
|
|
|
if test -x /usr/bin/eza
|
|
function ls
|
|
command eza -a --color=always --group-directories-first --icons=always $argv
|
|
end
|
|
function lr
|
|
command eza -al --color=always --group-directories-first --icons=always $argv
|
|
end
|
|
function ll
|
|
command eza -l --color=always --group-directories-first --icons=always $argv
|
|
end
|
|
function lt
|
|
command eza -aT --color=always --group-directories-first --icons=always $argv
|
|
end
|
|
function l.
|
|
command eza -ald --color=always --group-directories-first --icons=always .* $argv
|
|
end
|
|
function lf
|
|
command eza -aD --color=always --group-directories-first --icons=always $argv
|
|
end
|
|
else
|
|
for cmd in lr ll lt l. lf
|
|
function $cmd --inherit-variable cmd
|
|
echo "The command 'eza' is not installed. Please install 'eza' to use this: https://github.com/eza-community/eza"
|
|
end
|
|
end
|
|
end
|
|
|
|
################ BTOP #########################################################
|
|
|
|
if test -e /usr/bin/btop
|
|
alias tasks='btop'
|
|
end
|
|
|
|
################ MPV ##########################################################
|
|
|
|
if test -e /usr/bin/mpv
|
|
alias uni_play='mpv --vo=tct'
|
|
alias asci_play='mpv --vo=caca'
|
|
else
|
|
for cmd in uni_play asci_play
|
|
function $cmd --inherit-variable cmd
|
|
echo "The command 'mpv' is not installed. Please install mpv to use this: https://github.com/mpv-player/mpv"
|
|
end
|
|
end
|
|
end
|
|
|
|
################ GREP #########################################################
|
|
|
|
if test -e /usr/bin/ugrep
|
|
alias grep='ugrep --color=auto'
|
|
alias egrep='ugrep -E --color=auto'
|
|
alias fgrep='ugrep -F --color=auto'
|
|
else
|
|
alias egrep='grep -E'
|
|
alias fgrep='grep -F'
|
|
end
|
|
|
|
################ WGET #########################################################
|
|
|
|
if test -e /usr/bin/wget
|
|
alias wget='wget -c'
|
|
end
|
|
|
|
################ OCRMYPDF #####################################################
|
|
|
|
if test -e /usr/bin/ocrmypdf
|
|
alias ocrmypdf='ocrmypdf --deskew --clean --rotate-pages'
|
|
else
|
|
function ocrmypdf
|
|
echo "The command 'ocrmypdf' is not installed. Install it via your package manager: https://github.com/ocrmypdf/OCRmyPDF"
|
|
end
|
|
end
|
|
|
|
################ YAZI #########################################################
|
|
|
|
if test -e /usr/bin/yazi
|
|
function y
|
|
set tmp (mktemp -t "yazi-cwd.XXXXXX")
|
|
yazi $argv --cwd-file="$tmp"
|
|
if read -z cwd < "$tmp"; and [ -n "$cwd" ]; and [ "$cwd" != "$PWD" ]
|
|
builtin cd -- "$cwd"
|
|
end
|
|
rm -f -- "$tmp"
|
|
end
|
|
else
|
|
for cmd in yazi y
|
|
function $cmd --inherit-variable cmd
|
|
echo "The command 'yazi' is not installed. Please install 'yazi' to use this: https://github.com/sxyazi/yazi"
|
|
end
|
|
end
|
|
end
|
|
|
|
################ SUDO #########################################################
|
|
|
|
if test -e /usr/bin/sudo-rs
|
|
alias sudo=sudo-rs
|
|
end
|
|
|
|
################ FLASH ISO ####################################################
|
|
|
|
if test -e /usr/bin/dd
|
|
function flashiso --description "Flash an ISO to a target drive with dd"
|
|
if test (count $argv) -ne 2
|
|
echo "Usage: flashiso {ISO} {target drive}"
|
|
echo "Example: flashiso ubuntu-25.10-desktop-amd64.iso /dev/sdb"
|
|
return 1
|
|
end
|
|
sudo dd if=$argv[1] of=$argv[2] bs=4M status=progress oflag=sync
|
|
end
|
|
end
|
|
|
|
################ GIT ##########################################################
|
|
|
|
function git_cred
|
|
if test -f .git/config
|
|
# Check if the credential helper is already in the file
|
|
if grep -q "git-honney333-work-cred" .git/config
|
|
echo "Credential helper is already configured in .git/config"
|
|
else
|
|
echo "Adding Password tool to git"
|
|
# Append the blocks with a clean newline separator
|
|
echo -e "\n[credential]\n helper = !"$HOME"/.bin/git-honney333-work-cred" >> .git/config
|
|
end
|
|
else
|
|
echo "no .git/config file"
|
|
echo "could not add the credentials helper"
|
|
end
|
|
end |