forked from lahwaacz/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.bash_functions
More file actions
136 lines (112 loc) · 3.32 KB
/
Copy path.bash_functions
File metadata and controls
136 lines (112 loc) · 3.32 KB
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
135
136
#! /usr/bin/bash
## colored man pages
function man() {
env \
LESS_TERMCAP_mb=$'\e[01;31m' \
LESS_TERMCAP_md=$'\e[01;31m' \
LESS_TERMCAP_me=$'\e[0m' \
LESS_TERMCAP_se=$'\e[0m' \
LESS_TERMCAP_so=$'\e[01;44;33m' \
LESS_TERMCAP_ue=$'\e[0m' \
LESS_TERMCAP_us=$'\e[01;32m' \
man "$@"
}
## Print man pages
function manp() { man -t "$@" | lpr -pPrinter; }
## Create pdf of man page - requires ghostscript and mimeinfo
function manpdf() { man -t "$@" | ps2pdf - /tmp/manpdf_$1.pdf && xdg-open /tmp/manpdf_$1.pdf ;}
## lock all sessions when inactive for 300 seconds if in tty
#export TMOUT=300
#function TRAPALRM() {
# if [[ $(tty) != *pts* ]]; then
# vlock
# fi
#}
## h -- grep history
function h() {
fc -l 1 -1 | sed -n "/$1/s/^ */!/p" | tail -n 50
}
alias h=' h'
## fortune message
#if [[ $(setopt | grep login) == "login" ]]; then
# fortune ferengi_rules_of_acquisition
# echo
#fi
## simple notes taking utility
function n() {
local dir="$HOME/Bbox/Notes/"
local files=( "$@" )
# prepend $dir to each file
files=( "${files[@]/#/$dir}" )
${EDITOR:-vim} -p "${files[@]}"
}
function nls() {
find $HOME/Bbox/Notes/ -print0 | sort -z | xargs -0 ls -d --color=always | sed "1n; s|$HOME/Bbox/Notes/| ./|g; s|\./.*/[^$]| ./|g; s|\./||g"
# sed: skip first line; replace top-level directory with './'; replace '\./.*/[^$]' with ' ./'; delete all occurences of '\./'
}
# TAB completion for notes
function _n() {
local files=($HOME/Bbox/Notes/**/"$2"*)
[[ -e ${files[0]} ]] && COMPREPLY=( "${files[@]##~/Bbox/Notes/}" )
}
complete -o default -F _n n
## 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 ranger
# (reference: /usr/share/doc/ranger/examples/bash_automatic_cd.sh)
function ranger {
tempfile="$(mktemp -t ranger-cd.XXXXXX)"
/usr/bin/ranger --choosedir="$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
if [[ $(command -v rebuild-notify) ]] && [[ $(command -v expac) ]]; then
rebuild-notify
fi
}
alias suy='syu'