Skip to content

Commit 8ec6122

Browse files
authored
Merge pull request #1 from var-bin/fix-scripts
Fix scripts
2 parents 1b9db76 + 44decfa commit 8ec6122

File tree

7 files changed

+109
-58
lines changed

7 files changed

+109
-58
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ $ git clone https://github.com/var-bin/terminalForCoder__WSD.git
1414
## The list of topics
1515

1616
1. Terminal managers
17-
1. `screen`
17+
1. `screen` [[Follow this link]](https://github.com/var-bin/terminalForCoder__WSD/tree/master/screen)
1818
* Installation
1919
* Configuration file for `screen`
2020
* Basic key combinations
2121
* How it works
22-
2. `tmux`
22+
2. `tmux` [[Follow this link]](https://github.com/var-bin/terminalForCoder__WSD/tree/master/tmux)
2323
* Installation
2424
* Basic key combinations
2525
* How it works
26-
3. `screen` vs `tmux`
27-
2. `bash`
26+
3. `screen` vs `tmux` [[Follow this link]](https://github.com/var-bin/terminalForCoder__WSD/tree/master/screen-vs-tmux)
27+
2. `bash` [[Follow this link]](https://github.com/var-bin/terminalForCoder__WSD/tree/master/bash)
2828
1. Basic
2929
* Variables
3030
* Passing arguments to the script
@@ -37,7 +37,7 @@ $ git clone https://github.com/var-bin/terminalForCoder__WSD.git
3737
3. Loops for repeated code
3838
* `for/in`
3939
* `while`
40-
3. Routine tasks automation
40+
3. Routine tasks automation [[Follow this link]](https://github.com/var-bin/terminalForCoder__WSD/tree/master/bash/scripting)
4141
* Fast `diff`
4242
* Fast `diff` + `Jira API`
4343
* Clean _dist

bash/README.md

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The beginning of any script in bash
2828
**Read variable:**
2929

3030
```bash
31-
"$path" или "${path}"
31+
"$path" or "${path}"
3232
```
3333

3434
**Pass arguments to a script:**
@@ -153,7 +153,7 @@ The beginning of any script in bash
153153
echo "Removing dir"
154154
rm -r "$1"
155155
else
156-
echo "Can't remove ${1}"
156+
echo "Cannot remove ${1}"
157157
fi
158158
```
159159

@@ -242,33 +242,44 @@ The beginning of any script in bash
242242
```bash
243243
#!/bin/bash
244244

245+
PATH_TO_DIFF_DIR="${HOME}/diff/"
246+
FILE_EXTENTION=".diff"
247+
248+
USER_NAME="<user_name>"
249+
USER_PASSWORD="<user_password>"
250+
PROJECT_NAME="<project_name>"
251+
252+
# if "$1" is empty
245253
if [ -z "$1" ]
246254
then
247255
echo "Please, specify an issue ID"
248-
exit 1
256+
exit 0
249257
fi
250258

251259
issue_id="$1"
252260
branch=$(git rev-parse --abbrev-ref HEAD)
253261

254262
# Get the first line of git remote output and cut a path to repository
255263
repository=$(git remote -v | head -n1 | sed "s/^origin.*\/\(.*\)\.git\s(.*)/\1/")
264+
file_name="${branch}-${repository}${FILE_EXTENTION}"
256265

257-
path_to_diff="${HOME}/<path_to_diff_directory>${branch}-${repository}.diff"
266+
# path to diff directory with <filename>.diff
267+
path_to_diff="${PATH_TO_DIFF_DIR}${file_name}"
258268

259-
diff_live () {
260-
git diff "origin/live..master/${branch}" > "$path_to_diff"
269+
diffMaster() {
270+
git diff "origin/master origin/${branch}" > "$path_to_diff"
261271
}
262272

263-
attach_diff () {
264-
curl -D- -u "<ipa_username>":"<ipa_password>" -X POST -H "X-Atlassian-Token: no-check" -F "file=@${path_to_diff};type=text/x-diff" "https://jira.<project_name>.com/rest/api/2/issue/${issue_id}/attachments"
273+
attachDiff() {
274+
curl -D -u "${USER_NAME}":"${USER_PASSWORD}" -X POST -H "X-Atlassian-Token: no-check" -F "file=@${path_to_diff};type=text/x-diff" "https://jira.${PROJECT_NAME}.com/rest/api/2/issue/${issue_id}/attachments"
265275
}
266276

267-
diff_live && attach_diff
277+
diffMaster && attachDiff
268278

269-
# Usage: cd <repo_name> && attach_diff <issue_id>
279+
# Usage: cd <repo_name> && fast_diff_v2.sh <issue_id>
270280
# <issue_id> should include your company prefix (ABC, XYZ, XX, etc.)
271-
# At instance, "attach_diff XYZ-135" will try to attach diff to https://jira.<project_name>.com/browse/XYZ-135
281+
# At instance, "./fast_diff_v2.sh XYZ-135" will try to attach diff to
282+
# https://jira.<project_name>.com/browse/XYZ-135
272283
```
273284

274285
#### Up a large number of repositories
@@ -287,41 +298,56 @@ The beginning of any script in bash
287298
# get list of repositories
288299
findRepo() {
289300
REPO_NAME="terminalForCoder__WSD"
290-
path_to_vendor_repo="${HOME}/${REPO_NAME}/bash/core/vendors/"
291-
# find all git repositories in $path_to_vendor_repo
301+
PATH_TO_VENDORS_REPO="${HOME}/${REPO_NAME}/bash/core/vendors/"
302+
303+
# find all git repositories in $PATH_TO_VENDORS_REPO
292304
# filter by /.git
293-
r=$(find ${path_to_vendor_repo} -name .git | xargs | sed "s/\\/.git//g")
305+
306+
if [[ -e "$PATH_TO_VENDORS_REPO" ]]
307+
then
308+
r=$( find "$PATH_TO_VENDORS_REPO" -name .git | xargs | sed "s/\\/.git//g" )
309+
else
310+
echo "Cannot find ${PATH_TO_VENDORS_REPO}"
311+
echo "Try to edit REPO_NAME in ${0}"
312+
exit 0
313+
fi
314+
294315
# do check repositories stuff
295-
checkBranch "$r"
316+
checkBranch $r
296317
}
297318

298319
# do check repositories stuff
299320
checkBranch() {
300321
BRANCH="master"
322+
CHECK_BRANCH="* master"
301323

302-
# $i is item in $r
324+
# $i is an item in $r
303325
for i in "$@"
304326
do
305327
# get current branch name
306-
b=`cd ${i} && git branch | grep \*`
328+
b=$(cd "$i" && git branch | grep \*)
307329
echo "repo: ${i}"
308330
echo "current brunch: ${b}"
309331

310332
# check branch
311-
if [[ "$b" != "* master" ]]
333+
if [[ "$b" != "$CHECK_BRANCH" ]]
312334
then
313335
echo "!Error! ${i} is not on ${BRANCH} branch"
314336
echo "Current branch is ${b}"
337+
echo "Checkout to ${BRANCH} and do git pull stuff for ${i}"
315338
cd "$i" && git checkout "$BRANCH" && git branch && git pull origin "$BRANCH"
339+
echo ""
316340
else
317-
echo "Do pull stuff"
341+
echo "Do git pull stuff for ${i}"
318342
cd "$i" && git branch && git pull origin "$BRANCH"
343+
echo ""
319344
fi
320345
done
321346
echo "Done. Congratulation, you win!"
322347
}
323348

324349
findRepo "$@"
350+
325351
```
326352

327353
#### Helpful aliases

bash/clone_vendors.sh

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# clone vendors repositories to ./core/vendors
33
REPO_NAME="terminalForCoder__WSD"
44
PATH_TO_CORE="${HOME}/${REPO_NAME}/bash/core"
5+
PATH_TO_VENDORS_REPO="${HOME}/${REPO_NAME}/vendors"
56

67
# array with repositories
78
repositories=( "https://github.com/larscmagnusson/CSS3MultiColumn.git" "https://github.com/tc39/test262.git" "https://github.com/postcss/postcss" "https://github.com/webpack/webpack" "https://github.com/var-bin/spriteFactory.git" "https://github.com/var-bin/backbone-training.git" "https://github.com/var-bin/flex-grid-framework.git" "https://github.com/var-bin/BrandButtons.git" "https://github.com/var-bin/less-easings.git" )
@@ -10,11 +11,20 @@ i=0 # start el
1011
repositories_count=${#repositories[@]} # array size
1112

1213
cloneVendors() {
13-
# if "${PATH_TO_CORE}/vendors" is not exist
14-
# create "${PATH_TO_CORE}/vendors" directory
15-
if [[ ! -e "${PATH_TO_CORE}/vendors" ]]
14+
# if "${PATH_TO_CORE}" is not exist
15+
# show info message
16+
if [[ ! -e "${PATH_TO_CORE}" ]]
1617
then
17-
mkdir "${PATH_TO_CORE}/vendors"
18+
echo "Cannot find ${PATH_TO_CORE}"
19+
echo "Try to edit REPO_NAME in ${0}"
20+
exit 0
21+
fi
22+
23+
# if "${PATH_TO_VENDORS_REPO}" is not exist
24+
# create "${PATH_TO_VENDORS_REPO}" directory
25+
if [[ ! -e "${PATH_TO_VENDORS_REPO}" ]]
26+
then
27+
mkdir "${PATH_TO_VENDORS_REPO}"
1828
fi
1929

2030
while [ "$i" -lt "$repositories_count" ]
@@ -23,27 +33,28 @@ cloneVendors() {
2333
vendor=$(echo ${repositories[$i]} | sed "s/https\:\/\/github\.com\/*//g" | sed "s/\/.*//g")
2434
vendor_repo_name=$(echo ${repositories[$i]} | sed "s/https\:\/\/github\.com\/.*\///g" | sed "s/\.git//g")
2535

26-
# if "${PATH_TO_CORE}/vendors/${vendor}" is directory
36+
# if "${PATH_TO_VENDORS_REPO}/${vendor}" is directory
2737
# go to directory and do git clone stuff
28-
if [[ -d "${PATH_TO_CORE}/vendors/${vendor}" ]]
38+
if [[ -d "${PATH_TO_VENDORS_REPO}/${vendor}" ]]
2939
then
30-
echo "Directory ${PATH_TO_CORE}/vendors/${vendor} is exist"
40+
echo "Directory ${PATH_TO_VENDORS_REPO}/${vendor} is exist"
3141

32-
if [[ ! -e "${PATH_TO_CORE}/vendors/${vendor}/${vendor_repo_name}" ]]
42+
if [[ ! -e "${PATH_TO_VENDORS_REPO}/${vendor}/${vendor_repo_name}" ]]
3343
then
34-
cd "${PATH_TO_CORE}/vendors/${vendor}" && git clone ${repositories[$i]}
44+
echo "Repository: ${repositories[$i]} is clonning"
45+
cd "${PATH_TO_VENDORS_REPO}/${vendor}" && git clone ${repositories[$i]}
3546
else
36-
echo "Repository ${PATH_TO_CORE}/vendors/${vendor}/${vendor_repo_name} is exist"
47+
echo "Repository ${PATH_TO_VENDORS_REPO}/${vendor}/${vendor_repo_name} is exist"
3748
echo ""
3849
fi
3950
else
40-
# create directory "${PATH_TO_CORE}/vendors/${vendor}"
51+
# create directory "${PATH_TO_VENDORS_REPO}/${vendor}"
4152
# go to directory and do git clone stuff
42-
echo "Create directory: ${PATH_TO_CORE}/vendors/${vendor}"
43-
echo "Repository: ${repositories[$i]} is clonning"
53+
echo "Create directory: ${PATH_TO_VENDORS_REPO}/${vendor}"
54+
mkdir "${PATH_TO_VENDORS_REPO}/${vendor}"
4455

45-
mkdir "${PATH_TO_CORE}/vendors/${vendor}"
46-
cd "${PATH_TO_CORE}/vendors/${vendor}" && git clone ${repositories[$i]}
56+
echo "Repository: ${repositories[$i]} is clonning"
57+
cd "${PATH_TO_VENDORS_REPO}/${vendor}" && git clone ${repositories[$i]}
4758
fi
4859
i=$((i + 1)) # i++
4960
done

bash/scripting/clean_dist.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,22 @@ cleanDist() {
99
theme="$1"
1010
DIST_NAME="_dist"
1111
REPO_NAME="terminalForCoder__WSD"
12+
PATH_TO_CORE="${HOME}/${REPO_NAME}/bash/core"
1213

13-
PATH_TO_ASSETS="${HOME}/${REPO_NAME}/bash/core/assets"
14+
PATH_TO_ASSETS="${PATH_TO_CORE}/assets"
15+
16+
# if "${PATH_TO_CORE}" is not exist
17+
# show info message
18+
if [[ ! -e "${PATH_TO_CORE}" ]]
19+
then
20+
echo "Cannot find ${PATH_TO_CORE}"
21+
echo "Try to edit REPO_NAME in ${0}"
22+
exit 0
23+
fi
1424

1525
# if $1 == "" clean all _dist in each theme
1626
if [[ -z "$theme" ]]
1727
then
18-
theme="assets"
1928
path_to_dist="$PATH_TO_ASSETS"
2029
else
2130
path_to_dist="${PATH_TO_ASSETS}/${theme}"
@@ -24,10 +33,10 @@ cleanDist() {
2433
if [[ -n $(find "$path_to_dist" -type d -name "$DIST_NAME") ]]
2534
then
2635
# do clean stuff
27-
find "$path_to_dist" -type d -name "$DIST_NAME" | xargs -l rm -rfv
28-
echo "Dist of ${theme} have already deleted: ${path_to_dist}"
36+
find "$path_to_dist" -type d -name "$DIST_NAME" | xargs rm -rfv
37+
echo "Dist of ${theme} has already deleted: ${path_to_dist}"
2938
else
30-
echo "Can not find ${DIST_NAME} in ${theme}"
39+
echo "Cannot find ${DIST_NAME} in ${theme}"
3140
fi
3241
}
3342

bash/scripting/fast_diff.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ branch="$1"
1313
if [[ -z "$branch" ]]
1414
then
1515
echo "Enter the branch name"
16+
exit 0
1617
else
1718
path="${PATH_TO_DIFF_DIR}${FILE_PREFIX}${branch}${FILE_EXTENTION}"
1819
git diff origin/master origin/"$branch" > "$path"

bash/scripting/fast_diff_v2.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
PATH_TO_DIFF_DIR="${HOME}/diff/"
44
FILE_EXTENTION=".diff"
55

6-
USER_NAME="<ipa_user_name>"
7-
USER_PASSWORD="<ipa_user_password>"
6+
USER_NAME="<user_name>"
7+
USER_PASSWORD="<user_password>"
88
PROJECT_NAME="<project_name>"
99

1010
# if "$1" is empty
@@ -24,16 +24,17 @@ file_name="${branch}-${repository}${FILE_EXTENTION}"
2424
# path to diff directory with <filename>.diff
2525
path_to_diff="${PATH_TO_DIFF_DIR}${file_name}"
2626

27-
diff_master() {
27+
diffMaster() {
2828
git diff "origin/master origin/${branch}" > "$path_to_diff"
2929
}
3030

31-
attach_diff() {
31+
attachDiff() {
3232
curl -D -u "${USER_NAME}":"${USER_PASSWORD}" -X POST -H "X-Atlassian-Token: no-check" -F "file=@${path_to_diff};type=text/x-diff" "https://jira.${PROJECT_NAME}.com/rest/api/2/issue/${issue_id}/attachments"
3333
}
3434

35-
diff_master && attach_diff
35+
diffMaster && attachDiff
3636

3737
# Usage: cd <repo_name> && fast_diff_v2.sh <issue_id>
3838
# <issue_id> should include your company prefix (ABC, XYZ, XX, etc.)
39-
# At instance, "./fast_diff_v2.sh XYZ-135" will try to attach diff to https://jira.<project_name>.com/browse/XYZ-135
39+
# At instance, "./fast_diff_v2.sh XYZ-135" will try to attach diff to
40+
# https://jira.<project_name>.com/browse/XYZ-135

bash/scripting/up_repo.sh

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
# get list of repositories
1010
findRepo() {
1111
REPO_NAME="terminalForCoder__WSD"
12-
PATH_TO_VENDOR_REPO="${HOME}/${REPO_NAME}/bash/core/vendors/"
12+
PATH_TO_VENDORS_REPO="${HOME}/${REPO_NAME}/bash/core/vendors/"
1313

14-
# find all git repositories in $PATH_TO_VENDOR_REPO
14+
# find all git repositories in $PATH_TO_VENDORS_REPO
1515
# filter by /.git
1616

17-
if [[ -e "$PATH_TO_VENDOR_REPO" ]]
17+
if [[ -e "$PATH_TO_VENDORS_REPO" ]]
1818
then
19-
r=$( find "$PATH_TO_VENDOR_REPO" -name .git | xargs | sed "s/\\/.git//g" )
19+
r=$( find "$PATH_TO_VENDORS_REPO" -name .git | xargs | sed "s/\\/.git//g" )
2020
else
21-
echo "Can not find ${PATH_TO_VENDOR_REPO}"
22-
echo "Try to edit REPO_NAME"
21+
echo "Cannot find ${PATH_TO_VENDORS_REPO}"
22+
echo "Try to edit REPO_NAME in ${0}"
2323
exit 0
2424
fi
2525

@@ -30,6 +30,7 @@ findRepo() {
3030
# do check repositories stuff
3131
checkBranch() {
3232
BRANCH="master"
33+
CHECK_BRANCH="* master"
3334

3435
# $i is an item in $r
3536
for i in "$@"
@@ -40,13 +41,15 @@ checkBranch() {
4041
echo "current brunch: ${b}"
4142

4243
# check branch
43-
if [[ "$b" != "* master" ]]
44+
if [[ "$b" != "$CHECK_BRANCH" ]]
4445
then
4546
echo "!Error! ${i} is not on ${BRANCH} branch"
4647
echo "Current branch is ${b}"
48+
echo "Checkout to ${BRANCH} and do git pull stuff for ${i}"
4749
cd "$i" && git checkout "$BRANCH" && git branch && git pull origin "$BRANCH"
50+
echo ""
4851
else
49-
echo "Do pull stuff"
52+
echo "Do git pull stuff for ${i}"
5053
cd "$i" && git branch && git pull origin "$BRANCH"
5154
echo ""
5255
fi

0 commit comments

Comments
 (0)