-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdot_aliases
134 lines (120 loc) · 5.12 KB
/
dot_aliases
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Standard aliases
alias watchcpu='watch -n 1 "cat /proc/cpuinfo | grep \"^[c]pu MHz\""'
alias wetter2='curl http://v2.wttr.in/Nuremberg'
alias wetter='curl http://wttr.in/Nuremberg'
if [ -x "$(command -v nvim)" ]; then
alias vim='nvim'
fi
if [ -x "$(command -v eza)" ]; then
alias l="eza --color auto --group-directories-first --group --long --header --modified --sort=name --git --time-style=long-iso --classify --icons always"
alias ll="l -a"
alias lt="l --tree"
else
alias l="ls -l"
alias ll="l -a"
if [ -x "$(command -v tree)" ]; then
alias lt="tree"
fi
fi
alias pubip='curl ifconfig.co'
alias pubipv4='curl ifconfig.me'
if [ -x "$(command -v bat)" ]; then
alias cat="bat -pp"
fi
# fzf
if [ -x "$(command -v fzf)" ]; then
# fzf git aliases
## Select a branch with fzf and switch to it
alias gckof='git branch | fzf | cut --characters=3- | xargs --no-run-if-empty git checkout'
## Select a branch with fzf and merge it in the current branch
alias gmerf='git branch | fzf | cut --characters=3- | xargs --no-run-if-empty git merge'
## Output: abbreviated_commit_hash (%h) | commit_message (%s) | author_name (%an, in yellow) | commit_date_relative (%cr, in green)
alias glo='git lo'
## From the output of the glo alias, select with fzf the commit hash to rebase on
alias grebi='glo | fzf --ansi --no-sort | cut --delimiter=" " --fields=1 | xargs --no-run-if-empty -I % bash -c "</dev/tty git rebase --interactive %"'
## Select a commit with fzf and revert it
alias grevf='glo | fzf --ansi --no-sort | cut --delimiter=" " --fields=1 | xargs --no-run-if-empty git revert'
## Select a commit with fzf and show it
alias gshf='git shf'
alias gshft='git shft'
## Select a stash with fzf and show it
alias gstaf='git stash list | fzf --no-sort | sed -n "s/^stash@{\(.*\)}.*/\1/p" | xargs --no-run-if-empty git stash show'
# fzf docker aliases
## Select Docker containers and remove them (with its volumes)
alias drmf='docker ps --all | fzf --header-lines=1 --multi | tr --squeeze-repeats " " | cut --delimiter=" " --fields=1 | xargs --no-run-if-empty docker rm --volumes'
## Select Docker containers and stop them
alias dstopf='docker ps | fzf --header-lines=1 --multi | tr --squeeze-repeats " " | cut --delimiter=" " --fields=1 | xargs --no-run-if-empty docker stop'
## Select a Docker container and start shell in it
alias dexecf='docker ps | fzf --header-lines=1 --multi | tr --squeeze-repeats " " | rev | cut --delimiter=" " --fields=1 | rev | xargs --no-run-if-empty -I % bash -c "</dev/tty docker exec --interactive --tty % bash --login"'
## Select Docker images and remove them
alias drmif='docker image ls | fzf --header-lines=1 --multi | tr --squeeze-repeats " " | cut --delimiter=" " --fields=3 | xargs --no-run-if-empty docker rmi --force'
# fzf SSH aliases
## list all hosts in ~/.ssh/config and ssh into it
alias sf='ssh $(grep "Host " ~/.ssh/config | cut -c 6- | fzf --no-sort --multi=1)'
fi
# Distrobox
if [ -x "$(command -v distrobox)" ]; then
alias de='distrobox enter'
alias emacsclient='distrobox enter dev -- emacsclient'
alias emacs='distrobox enter dev -- emacs'
fi
# Functions
mkcd () {
mkdir -p -- "$1" &&
cd -P -- "$1"
}
## Spell check if aspell is installed
if [ -x "$(command -v aspell)" ]; then
sc () {
echo "$@" | aspell -a
}
fi
# Allow sudo to use user aliases
alias sudo='sudo '
# SUSE internal build service instance
if [ -x "$(command -v osc)" ]; then
alias isc='osc -A https://api.suse.de'
fi
# ssh with automatic sourcing of aliases
# Be very careful with this, as it sources external files and can do a lot of damage
function sshs() {
ssh -t $1 "bash --rcfile <(curl https://w3.suse.de/~jcronenberg/aliases || curl https://raw.githubusercontent.com/jcronenberg/dotfiles/master/dot_aliases)"
}
# Add a TODO entry to agenda from cli
function todo() {
echo "**** TODO $@" >> /home/jcronenberg/Nextcloud/org/roam/agenda.org
}
# git interactive rebase $1 amount from HEAD
function gri() {
git rebase -i HEAD~$1
}
function typos-patch() {
cat $1 | sed -n -e '/^+/p' | typos -
}
# Build a local rpm at ~/rpmbuild
if [ -x "$(command -v rpmbuild)" ]; then
alias local-rpmbuild='rpmbuild -bi --with check ~/rpmbuild/SPECS/*.spec'
fi
# Open file on host if the session is a SSH connection
# This is highly not portable and basically is only designed
# to work with my vagrant dev box
if [ ! -z "$SSH_CLIENT" ]; then
function eos() {
for file in "$@"; do
ssh jcronenberg@`echo $SSH_CLIENT | awk '{print $1}'` -i ~/.ssh/jcronenberg_private "emacsclient -n `print -rD $PWD`/$file &> /dev/null || distrobox enter dev -- emacsclient -n `print -rD $PWD`/$file &> /dev/null"
done
}
function scopy() {
cat "$@" | ~/bin/host-copy
}
function host-exec () {
ssh jcronenberg@`echo $SSH_CLIENT | awk '{print $1}'` -i ~/.ssh/jcronenberg_private $@
}
fi
# Awesome notification when command is finished
if [ -x "$(command -v awesome-notify)" ]; then
notify-after() {
$@
awesome-notify "\\\"$@\\\" has finished"
}
fi