-
Notifications
You must be signed in to change notification settings - Fork 9
/
.bash_functions
83 lines (71 loc) · 1.83 KB
/
.bash_functions
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
#! /usr/bin/bash
## h -- grep history
function h() {
fc -l 1 -1 | sed -n "/$1/s/^ */!/p" | tail -n 50
}
alias h=' h'
## simple notes taking utility
function n() {
local dir="$HOME/Documents/Notes/"
(
builtin cd "$dir"
nvim -c NvimTreeOpen todo.md
)
}
## frequently used pacman commands
function orphans() {
if [[ ! -n $(pacman -Qdtt) ]]; then
echo "no orphans to remove"
else
sudo pacman -Rnsc $(pacman -Qdttq)
fi
}
## custom cd function
# implements 'autopushd'
# 'cd -' flips last visited dir (exactly what pushd without aruments does)
function cd() {
if [[ $# -eq 0 ]]; then
builtin pushd "$HOME"
else
# remove '--' from the parameters
if [[ "$1" == "--" ]]; then
set -- "${@:2:$#}"
fi
if [[ $# -eq 1 ]]; then
if [[ "$1" == "-" ]]; then
builtin pushd
elif [[ -f "$1" ]]; then
# auxiliary variable is necessary to handle spaces in the path
local dir
dir=$(dirname "$1")
builtin pushd -- "$dir"
else
builtin pushd -- "$1"
fi
else
echo "cd: Too many arguments"
fi
fi
}
## path synchronization for lf
# (reference: https://github.com/gokcehan/lf/blob/master/etc/lfcd.sh)
function lf {
tempfile="$(mktemp -t lf-cd.XXXXXX)"
command lf -last-dir-path="$tempfile" "${@:-$(pwd)}"
if [[ -f "$tempfile" ]] && [[ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]]; then
cd -- "$(cat "$tempfile")"
fi
rm -f -- "$tempfile"
}
## system upgrade
function syu {
sudo pacman -Syu $@
local ret=$?
if [[ $ret -ne 0 ]]; then
return $ret
fi
if [[ $(command -v checkservices) ]]; then
sudo checkservices
fi
}
alias suy='syu'