-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell_functions.sh
66 lines (56 loc) · 1.59 KB
/
shell_functions.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
pc () {
python -c "print($1)"
}
tmux_update_display () {
export DISPLAY="$(tmux show-env | grep ^DISPLAY | sed -n 's/^DISPLAY=//p')"
}
put_first_in_path () {
stripped_path=${PATH}
new_path="$(readlink -e "${1}")"
if [[ -z ${new_path} ]] then
echo "${1} does not exist!"
return
fi
stripped_path="$(sed "s#${new_path}##g" <<< "${stripped_path}" | sed 's/::/:/g')"
export PATH="${new_path}:${stripped_path}"
}
add_to_path () {
[[ "$PATH" == *$1* ]] || export PATH="${1}:${PATH}"
}
projects_file="$DOTFILES/projects.txt"
name_dir_separator=" -> "
fzf_projects_cd () {
if [[ -n "${1}" ]] then
if ! command -v rg &> /dev/null; then
echo "Install rg first please!"
return 1
fi
result=$(rg "${1}.*${name_dir_separator}" "${projects_file}")
if [[ $(wc -l <<< ${result}) -eq "1" ]] then
directory="$result"
else
directory=$(cat "${projects_file}" | fzf -q "${1}")
fi
else
directory=$(cat "${projects_file}" | fzf)
fi
if [[ -z ${directory} ]] then
echo "Nothing chosen."
return # fzf was probably escaped
fi
echo "${directory}"
dir=$(echo "${directory}" | awk -F"${name_dir_separator}" '{print $2}')
cd "${dir}"
}
fzf_projects_add () {
name=${1}
dir=${2}
if [[ -z ${dir} || ${dir} = "." ]] then
dir=$(pwd)
fi
if [[ -z ${name} ]] then
name="$(basename "$dir")"
fi
echo "${name}${name_dir_separator}${dir}" >> "${projects_file}"
}
verlte() { printf '%s\n%s' "$1" "$2" | sort -C -V; }