Skip to content

Commit 0cabcaa

Browse files
devydevy
authored andcommitted
update functions/github.sh
1 parent 0e680d7 commit 0cabcaa

1 file changed

Lines changed: 91 additions & 1 deletion

File tree

functions/github.sh

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,94 @@ function git_changes() {
123123
echo "--------------------------------"
124124
}
125125
alias gch="git_changes"
126-
alias changes="git_changes"
126+
alias changes="git_changes"
127+
128+
# function to lazily add commit and push
129+
function lazy_push() {
130+
# Check if argument is provided
131+
if [ -z "$1" ]; then
132+
echo "Usage: lazy_push <file_path>"
133+
echo "Example: lazy_push 'config/stow/aerospace/*'"
134+
return 1
135+
fi
136+
137+
# Generate commit message based on file path
138+
local file_path="$1"
139+
local commit_message=""
140+
local fomatted_commit_message=""
141+
142+
# Remove trailing slash if present
143+
file_path=$(echo "$file_path" | sed 's/\/$//')
144+
# echo 'file path after removing trailing slash: ' $file_path
145+
# Remove trailing asterisks if present
146+
file_path=$(echo "$file_path" | sed 's/\*$//')
147+
# echo 'file path after removing asterisks: ' $file_path
148+
149+
# Split the path into parts using parameter expansion
150+
path_parts=(${(s:/:)file_path})
151+
152+
# echo 'path parts: ' ${path_parts[@]}
153+
154+
# Get the last part (file or folder name)
155+
local last_part="${path_parts[-1]}"
156+
# echo 'last part: ' $last_part
157+
158+
# Get the first part (first folder)
159+
local first_part="${path_parts[1]}"
160+
# echo 'first part: ' $first_part
161+
162+
# Remove file extension from last part if it's a file
163+
last_part=$(echo "$last_part" | sed 's/\.[^.]*$//')
164+
# echo 'last part after removing file extension: ' $last_part
165+
166+
# Generate commit message
167+
if [[ ${#path_parts[@]} -eq 1 ]]; then
168+
# Single file/folder
169+
commit_message="${last_part}"
170+
else
171+
# Multiple parts: "{last_part} {first_part}"
172+
commit_message="${last_part} ${first_part}"
173+
fi
174+
175+
# Check if second argument is provided and modify commit message accordingly
176+
if [[ -n "$2" && ("$2" == "a" || "$2" == "add") ]]; then
177+
fomatted_commit_message="${blue} add ${reset} ${commit_message#update }"
178+
commit_message="add ${commit_message#update }"
179+
elif [[ -n "$2" && ("$2" == "aa") ]]; then
180+
fomatted_commit_message="${blue} add ${reset} ${commit_message#update }"
181+
commit_message="add ${commit_message#update }"
182+
183+
# Remove trailing 's' from commit message if present
184+
fomatted_commit_message=$(echo "$fomatted_commit_message" | sed 's/s$//')
185+
commit_message=$(echo "$commit_message" | sed 's/s$//')
186+
elif [[ -n "$2" && ("$2" == "s" || "$2" == "sub" || "$2" == "subtract") ]]; then
187+
fomatted_commit_message="${red} remove ${reset} ${commit_message#update }"
188+
commit_message="remove ${commit_message#update }"
189+
else
190+
fomatted_commit_message="${yellow} update ${reset} ${commit_message#update }"
191+
commit_message="update ${commit_message#update }"
192+
fi
193+
194+
195+
# todo: probably a good candidate for go commander style cli tool to add flags
196+
# such that if -s or similar is passed it will remove the s from the "last_part"
197+
# before generating a a message
198+
199+
# Generate commit message
200+
# if [[ -z "$first_folder" ]]; then
201+
# commit_message="update ${last_part}"
202+
# elif [[ "$first_folder" == "config" ]]; then
203+
# commit_message="update ${last_part} $first_folder"
204+
# fi
205+
206+
207+
echo "${green}Lazy pushing 🎉${reset}"
208+
echo "${orange}commit message: ${reset}${fomatted_commit_message}${reset}"
209+
# echo "actual commit message: ${commit_message}"
210+
# echo " \j
211+
#
212+
git add $1 &&
213+
git commit -m "update $1" &&
214+
git push
215+
}
216+
alias lgap="lazy_push"

0 commit comments

Comments
 (0)