-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_functions
executable file
·38 lines (34 loc) · 1020 Bytes
/
_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
#!/bin/bash
# Ref: https://stackoverflow.com/a/10660730/1231095
rawurlencode() {
local string="${1}"
local strlen=${#string}
local encoded=""
local pos c o
for ((pos = 0; pos < strlen; pos++)); do
c=${string:$pos:1}
case "$c" in
[-_.~a-zA-Z0-9]) o="${c}" ;;
*) printf -v o '%%%02x' "'$c" ;;
esac
encoded+="${o}"
done
echo "${encoded}" # You can either set a return variable (FASTER)
REPLY="${encoded}" #+or echo the result (EASIER)... or both... :p
}
# Return 1 if branch name exists locally, undefined if not
# E.g. >>> if [[ -z $(gitBranchExistsInLocal $branchName) ]]; then
gitBranchExistsInLocal() {
local branch="${1}"
if [[ $(git branch --list "$branch") ]]; then
echo 1
fi
}
# Return 1 if branch name exists remotely, undefined if not
# E.g. >>> if [[ -z $(gitBranchExistsInRemote $branchName) ]]; then
gitBranchExistsInRemote() {
local branch=${1}
if [[ $(git ls-remote --heads origin "$branch") ]]; then
echo 1
fi
}