mirror of
https://codeberg.org/vlw/dotfiles.git
synced 2025-09-13 19:03:40 +02:00
132 lines
3.1 KiB
Bash
132 lines
3.1 KiB
Bash
# Shorter exit - I'm lazy
|
|
alias e="exit"
|
|
# Change PHP CLI binary
|
|
alias phpa="sudo update-alternatives --config php"
|
|
# Kill all code-server processes. Sometimes it hangs on startup
|
|
alias kvscode="ps uxa | grep .vscode-server | awk '{print $2}' | xargs kill -9"
|
|
|
|
# Tmux split commands, "q" for fast access, "w" for horizontal (right of q), "a" for vertical (below q)
|
|
alias qw="tmux split-window -h"
|
|
alias qa="tmux split-window -v"
|
|
|
|
# +-------------------+
|
|
# | Directory & Files |
|
|
# +-------------------+
|
|
|
|
# Preview contents of a file or list the contents of a directory
|
|
l () {
|
|
if [ -f "$1" ] ; then
|
|
less $1
|
|
return
|
|
fi
|
|
|
|
ls -lh $1 || l $(dirname "$1")
|
|
}
|
|
|
|
# Preview the contents of a file or list the contents of a directory with hidden files shown
|
|
ll () {
|
|
if [ -f "$1" ] ; then
|
|
less $1
|
|
return
|
|
fi
|
|
|
|
ls -lah $1 || ll $(dirname "$1")
|
|
}
|
|
|
|
# Edit the contents of a file or list the contents of a directory (with hidden files shown) if that file is not found
|
|
lll () {
|
|
if [ -f "$1" ] ; then
|
|
nano $1
|
|
return
|
|
fi
|
|
|
|
ls -lah $1 || lll $(dirname "$1")
|
|
}
|
|
|
|
.. () {
|
|
cd .. && l
|
|
}
|
|
|
|
cdl () {
|
|
# Cdl to home if no args provided
|
|
if [ $# -eq 0 ]; then
|
|
cdl $HOME
|
|
fi
|
|
|
|
cd -P -- "$1" && l
|
|
}
|
|
|
|
cdll () {
|
|
# Cdll to home if no args provided
|
|
if [ $# -eq 0 ]; then
|
|
cdll $HOME
|
|
fi
|
|
|
|
cd -P -- "$1" && ll
|
|
}
|
|
|
|
# Make a new directory and cd into it
|
|
mkcdir () {
|
|
mkdir -p -- "$1" && cd -P -- "$1"
|
|
}
|
|
|
|
# +-----+
|
|
# | Git |
|
|
# +-----+
|
|
|
|
# Short-hands for various git functions
|
|
gitf () {
|
|
case "$1" in
|
|
# Stage all changes and fall through to WIP commit
|
|
"aw")
|
|
git add .
|
|
gitf w
|
|
;;
|
|
|
|
# Clear local branches that have no upstream on remote (cleanup)
|
|
"c")
|
|
git fetch -p && git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -D
|
|
;;
|
|
|
|
# Pull current branch from a remote (defaults to "origin"). "d" for download.
|
|
"d")
|
|
local remote="${2:-origin}"
|
|
|
|
git pull "$remote" $(git rev-parse --abbrev-ref HEAD)
|
|
;;
|
|
|
|
# Update all git submodules in this repo. "sd" for submodule download.
|
|
"sd")
|
|
# Only supports "master" as branch for now. This could cause unexpected results if a tracked submodule has a different branch or location name
|
|
git submodule foreach "(git checkout master; git pull)"
|
|
;;
|
|
|
|
# Push commited changes (current branch) to a remote (defaults to "origin"). "u" for upload.
|
|
"u")
|
|
local remote="${2:-origin}"
|
|
|
|
git push --set-upstream "$remote" $(git rev-parse --abbrev-ref HEAD)
|
|
;;
|
|
|
|
# Create a git "Work in Progress" commit with timestamps
|
|
"w")
|
|
git commit -m "wip: $(date +%Y-%m-%dT%H:%M:%S%z) ($(date +%s))"
|
|
;;
|
|
|
|
*)
|
|
git status
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# +-----+
|
|
# | SSH |
|
|
# +-----+
|
|
|
|
# SSH to machine in debug mode at local.vlw.se
|
|
sshl () {
|
|
# Set login name from first argument or default to current user
|
|
local user="${1:-$(whoami)}"
|
|
|
|
ssh -p 2222 "$user"@local.vlw.se
|
|
}
|