forked from tu-graz-library/invenio-life-hacks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_funcs
91 lines (78 loc) · 2.4 KB
/
.bash_funcs
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
# Copyright (C) 2021 Graz University of Technology.
# Search strings in files like
# fxgrep py RecordService
#
# find RecordService in *.py python files and exclude all files comming from
# directories which include invenio-rdm-records or test
# fxgrep py RecordService invenio-rdm-records test
#
# find RecordService in *.py files where RecordService prefix and suffix is not
# a character
# fxgrep py '[^a-z]RecordService[^a-z]'
#
# default is to search case insensitive, but sometimes it is easier to search
# case sensitive. the search string has to be prefixed with "i:"
# fxgrep py i:Owner
function fxgrep() {
xagr="xargs grep -n -P --color"
notpaths=()
space=$1
pattern=$2
if [[ ${pattern:0:2} == "i:" ]]
then
pattern=${pattern:2}
else
xagr+=" -i"
fi
for (( i=3; i <= $#; i++ ))
do
notpaths+=( -not -path "*${!i}*")
done
if [[ ${space} == "c++" ]]
then
file_extensions=".*\.(cpp|hpp|cc|c|h)"
elif [[ ${space} == "html" ]]
then
file_extensions=".*\.(html|less|css)"
elif [[ ${space} == "js" ]]
then
file_extensions=".*\.(js|jsx|svelte|ts|vue)"
notpaths+=( -not -path "*build*" )
notpaths+=( -not -path "*node_modules*" )
elif [[ ${space} == "php" ]]
then
file_extensions=".*\.(php|tpl)"
elif [[ ${space} == "xml" ]]
then
file_extensions=".*\.(xml|xsl)"
elif [[ ${space} == "tex" ]]
then
file_extensions=".*\.tex"
elif [[ ${space} == "py" ]]
then
file_extensions=".*\.py"
else
file_extensions=".*${space}"
fi
find -type f -regextype posix-egrep -regex ${file_extensions} "${notpaths[@]}" | sed 's/ /\\ /g' | $xagr ${pattern}
}
# show the name of the current git branch
function gitBranch() {
git branch 2> /dev/null | sed -r -e '/^[^*]/d' -e 's/\* (.+)$/(\1) /'
}
# see if there is a open ssh session. the possible name of the session could be
# detected also in the sed command like 's/^(ssh).*(Max|Moritz).*/(\1@\2) /'. it
# would be clearer which session is open
function isSSHActive() {
ssh-add -L 2> /dev/null | sed -r -e 's/^(ssh).*/(\1) /'
}
# the bash prompt could be overriden. to use it like that put the "bash_prompt"
# command into the .bashrc file
function bash_prompt() {
local none="\[\e[00m\]"
local red="\[\e[31m\]"
local green="\[\e[32m\]"
local boldBlue="\[\e[01;34m\]"
local white="\[\e[37m\]"
export PS1="${white}\u ${green}\$(isSSHActive)${boldBlue}\W ${red}\$(gitBranch)${none}\$${none} "
}