5 ms·
For his usecase of funky i use ~/.bash_aliases, that way i can easily share them between machines. Eg to quickly add a new one: alias als="nvim $HOME/.bash_alia
by scns 5y ago
For his usecase of funky i use ~/.bash_aliases, that way i can easily share them between machines. Eg to quickly add a new one: alias als="nvim $HOME/.bash_aliases && source $HOME/.bash_aliases"
Be careful with quoting though, got myself into a situation where every new terminal asked for the root password. Shellcheck found the reason quickly.
(edit) Another benefit is that those aliases abstract over differences of invocation on different distros. Here are some examples:
# PACKAGE MANAGEMENT
alias pcl="sudo zypper cc && sudo zypper purge-kernels"
alias pin="sudo zypper install -y"
alias pla="zypper search"
alias pli="zypper packages --installed-only | rg "
alias plu="zypper list-updates && zypper list-patches"
alias pre="sudo zypper remove"
alias pup="far too long" # upgrade all packages and ask for confirmation
alias pups="far too long + shutdown" # upgrade all packages without confirmation && shut down
# QUICK EDITS
alias als="nvim ~/.alias && source ~/.alias"
alias brc="nvim ~/.bashrc && source ~/.bashrc"
alias egr="sudo nvim /etc/default/grub && sudo update-grub"
alias fst="sudo nvim /etc/fstab"
alias pro="nvim ~/.profile && source ~/.profile"
# QUICK MOVEMENTS
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias sc="shellcheck"
# SYSTEMD
alias sden="sudo systemctl enable --now"
alias sdls="sudo systemctl --type=service"
alias sds="sudo systemctl start"
# VIM
alias nrc="cd ~/.config/nvim/ && nvim init.lua"
alias nv="nvim"
alias scratch="nvim scratch.txt"
- modernerd 5y agoI used to alias .. etc., but then found that Fish shell has helpful commands and behaviours for directory navigation built in: > Note that the shell will attempt to change directory without requiring cd if the name of a directory is provided (starting with ., / or ~, or ending with /). > https://fishshell.com/docs/current/cmds/cd.html https://fishshell.com/docs/current/cmds/cd.html So these all work without the cd by default with Fish: ../ ../../ ~ ~/path/to/folder cdh is also very useful. It shows a history of recent directories with a keyed prompt to jump to a directory. https://fishshell.com/docs/current/cmds/cdh.html https://fishshell.com/docs/current/cmds/cdh.html
- wruza 5y agoI’m also a heavy user of aliases and can’t see how I’d use funky. Behavior dependent on a current directory is rarely a good idea, and when it is, you can just create an explicit shell ./script
- jazzyjackson 5y agoFunny, never occurred to me to make shortcuts out of .., I like that
- sandreas 5y agoInstead of creating aliases for .., I use this: function ..() { for i in $(seq 1 $1); do cd ..; done } which enables .. # up 1 dir .. 2 # up 2 dirs .. 42 # up 42 dirs Here are some more: https://pilabor.com/blog/2021/03/unix-shell-tricks/ https://pilabor.com/blog/2021/03/unix-shell-tricks/
- aidos 5y agoClever. Never seen that idea before.
- LilBytes 5y agoThat's amazing.
- ozym4nd145 5y agoThis might be a better alternate to preserve functionality of `cd -` function ..() { cd $(printf '../%.0s' $(seq 1 $1)) }
- sandreas 5y agoMmh, what do you mean with "preserve"...? `cd -` works like a charm for me.
- makeworld 5y ago"cd -" changes to the previous working directory. Your function calls cd multiple times, so calling "cd -" won't bring the user to the previous working directory they expect. ozym4nd145's function only calls cd once.
- sandreas 5y agoAah, now I see. Awesome, I'll try that out. Thank you.
- vbernat 5y agoWith Zsh, I am using: # Expand ... to ../.. function vbe-expand-dot-to-parent-directory-path() { case $LBUFFER in (./..|* ./..) LBUFFER+='.' ;; # In Go: "go list ./..." (..|*[ /=]..) LBUFFER+='/..' ;; (*) LBUFFER+='.' ;; esac } zle -N vbe-expand-dot-to-parent-directory-path bindkey "." vbe-expand-dot-to-parent-directory-path bindkey -M isearch "." self-insert
- depingus 5y agoYou can put sudo in an alias!? [mindblown.gif]