-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminal-aliases.plugin.zsh
132 lines (112 loc) · 5.12 KB
/
terminal-aliases.plugin.zsh
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
# Description: Aliases for terminal, git, terraform and more
#
# Author: https://github.com/dvir-levy
# =============================================================================
function has_command() {
which "$@" > /dev/null 2>&1
}
# Check if WORKSPACE_PATH is set
if [[ -z "$WORKSPACE_PATH" ]]; then
echo "Error: WORKSPACE_PATH is not set. Please configure it in your environment."
return 1
fi
# Terminal
alias ll='ls -lGHa'
# AWS
if has_command aws && has_command aws-sso-login; then
alias gl="echo 'currently working with:' && head -n1 $HOME/.aws/config && aws-sso-login"
fi
# Define a function to set CD aliases
set_cd_aliases() {
local workspace_path="$1"
# Get a list of all repositories in the workspace path
all_repositories=("$workspace_path"/*)
# Set aliases for each repository
for repo in "${all_repositories[@]}"; do
repo_name=$(basename "$repo")
if [[ $repo_name == *terraform* ]]; then
alias "$repo_name"="cd $repo && alias tfall='terraform fmt --recursive $WORKSPACE_PATH/$repo_name' && ls -la"
else
alias "$repo_name"="cd $repo && ls -la"
fi
done
}
set_cd_aliases $WORKSPACE_PATH
# Terraform
if has_command terraform ; then
alias tfall='terraform fmt -recursive $WORKSPACE_PATH'
alias tf="terraform fmt -recursive"
alias tia='ti && ta'
alias tip='ti && tp'
alias ta="terraform apply"
alias td="terraform destroy"
alias ti="terraform init"
alias tia='ti && ta'
alias tip='ti && tp'
alias to="terraform output"
alias tp="tfall && terraform plan"
alias ts="terraform state"
alias tu="terraform force-unlock -force"
alias tv="terraform validate"
alias cleanup='echo | find $WORKSPACE_PATH -type d -name .terraform | xargs rm -rf'
alias renewproviders='rm -rf ./.terraform.lock.hcl && terraform providers lock -platform=linux_amd64 -platform=darwin_amd64'
fi
# git
if has_command git ; then
alias gsu='git submodule update --init --recursive'
alias gcm='git checkout $(git_main_branch) && git pull'
alias gam='function _gam() { git add -A && git commit --verbose -m "$*" && git push; }; _gam' # git add, commit and push all together. run: 'gam "this is commit"'
alias dlb='stale_branch=$(git branch --show-current) && git checkout $(git_main_branch) && git pull && git branch -d $stale_branch' #delete local branch, checkout main and pull
alias fullrebase='current_branch=$(git branch --show-current) && git checkout $(git_main_branch) && git pull && git checkout $current_branch && git rebase $(git_main_branch)' #rebase current branch, run 'git push -f' right after if there are no conflicts
alias fullmerge='current_branch=$(git branch --show-current) && git checkout $(git_main_branch) && git pull && git checkout $current_branch && git merge $(git_main_branch)' #merge current branch, run 'git push -f' right after if there are no conflicts
alias dlg='git fetch --prune && git branch --merged $(git_main_branch) | grep -v "^[ *]*$(git_main_branch)$" | xargs git branch -d' #delete local branches that were merged to main
fi
# creates new GitHub Pull Request. optional jira ticket id (e.g:1234). run: 'newpr test_pr 1234'
if has_command terraform && has_command git; then
newpr() {
BPurple='\033[1;35m'
Color_Off='\033[0m'
Green='\033[0;102m'
echo "terraform format"
tfall
echo "${BPurple}git status:${Color_Off}"
gst
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
echo "${BPurple}switching to master and pull...${Color_Off}"
git checkout $(git_main_branch)
git pull
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
echo "${BPurple}creating new branch...${Color_Off}"
git branch "$1"
git checkout "$1"
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
echo "${BPurple}git status:${Color_Off}"
gst
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
echo "${BPurple}staging all commits...${Color_Off}"
ga -A
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
echo "${BPurple}git status:${Color_Off}"
gst
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
echo "${BPurple}commiting first commit...${Color_Off}"
gc -m "$2 - $1"
ga -A
gc -m "$2 - $1"
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
echo "${BPurple}pushing branch to remote...${Color_Off}"
RESULT=$(git push --set-upstream origin $1 2>&1 1>/dev/null | cat)
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' '*'
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' '*'
HTTP=$(echo $RESULT | grep -o 'https://[0-9a-zA-Z.]*\/.*\S')
echo "Opening GitHub to create new pr :)"
echo "${Green}$HTTP${Color_Off}"
sleep 2
open $HTTP
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' '*'
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' '*'
echo "${BPurple}git status:${Color_Off}"
gst
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
}
fi