-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction.sh
executable file
·80 lines (71 loc) · 1.93 KB
/
function.sh
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
# Can't put this in ~/scripts/function.sh, The shell exits with lf
lfcd_old() {
tmp="$(mktemp)"
lf -last-dir-path="$tmp" "$@"
if [ -f "$tmp" ]; then
dir="$(cat "$tmp")"
rm -f "$tmp"
[ -d "$dir" ] && [ "$dir" != "$(pwd)" ] && cd "$dir" || exit
fi
}
lfcd() {
# `command` is needed in case `lfcd` is aliased to `lf`
cd "$(command lf -print-last-dir "$@")" || exit
}
y() {
local tmp="$(mktemp -t "yazi-cwd.XXXXXX")"
yazi "$@" --cwd-file="$tmp"
if cwd="$(cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
cd -- "$cwd" || exit
fi
rm -f -- "$tmp"
}
# Package Manager
pm() {
pacman -Slq | fzf -m --preview='pacman -Si {}' --height 100% --bind='enter:execute(paru -S {+})+abort'
}
# Pacman Preview Explicitly Installed
ppi() {
pacman -Qeq | fzf --preview 'pacman -Qil {}' --height 100% --layout=reverse --bind 'enter:execute(pacman -Qil {} | less)'
}
# Pacman Preview All Installed
ppa() {
pacman -Qq | fzf --preview 'pacman -Qil {}' --layout=reverse --bind 'enter:execute(pacman -Qil {} | less)'
}
rename_directories() {
for dir in "$1"/*; do
if [ -d "$dir" ]; then
file=$(basename "$dir"/*)
dir_path=$(dirname "$dir")
mv "$dir" "$dir_path/$file"
echo "Renamed '$dir' to '$dir_path/$file'"
fi
done
}
# Taken from a reddit post of fastfetch config
age() {
birth_install=$(stat -c %W /)
current=$(date +%s)
time_progression=$((current - birth_install))
days_difference=$((time_progression / 86400))
echo $days_difference days
}
most_used() {
history |
awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' |
grep -v "./" |
column -c3 -s " " -t |
sort -nr |
nl |
head -n "$1"
}
# This needs to be defined in root user.
# recovery-pacman() {
# pacman "$@" \
# --log /dev/null \
# --noscriptlet \
# --dbonly \
# --overwrite "*" \
# --nodeps \
# --needed
# }