@@ -5,6 +5,22 @@ alias j=jira
55alias mytasks=" jira issue list -a amro -s~Done"
66
77alias dev=" dex dill_devcontainer zsh"
8+ alias pl=pickle-tui
9+ bindkey -s ' ^[o' ' pickle-tui^M'
10+
11+ function get_rot() {
12+ r=${1}
13+ p=${2}
14+ y=${3}
15+ should_copy=${4:- 0}
16+ echo " RPY: ${r} ${p} ${y} [deg]."
17+ echo " Should copy: ${should_copy} "
18+ output=$( euler -e -s xyz -p --ros -- ${1} ${2} ${3} )
19+ if [[ ${should_copy} -eq 1 ]]; then
20+ echo " ${output} " | tail -n 6 | xclip -selection clipboard
21+ echo " Copied quaternion to clipboard."
22+ fi
23+ }
824
925
1026# ROS workspace in rosbridge
@@ -163,6 +179,213 @@ function kr70fk() {
163179 docker exec -it dill_devcontainer python -c " from app.arm.kuka.kinematics.kinematics import make_kr70_kin; kin = make_kr70_kin(None); print(kin.forward(${q} ))"
164180}
165181
182+ # Function to delete git branches
183+ delete-branch () {
184+ # Check for help option first
185+ if [[ " $1 " == " -h" || " $1 " == " --help" ]]; then
186+ echo " Usage: delete-branch [-f] [-l | -r] [--fzf] <branch-name> [<branch-name> ...]"
187+ echo " Delete git branches locally and/or remotely."
188+ echo " "
189+ echo " Options:"
190+ echo " -f Force delete (use -D instead of -d for local branches)"
191+ echo " -l Delete only local branches"
192+ echo " -r Delete only remote branches"
193+ echo " --fzf Use fzf to interactively select branches to delete"
194+ echo " -h, --help Show this help message"
195+ echo " "
196+ echo " Arguments:"
197+ echo " <branch-name> Name(s) of branch(es) to delete (ignored when --fzf is used)"
198+ echo " "
199+ echo " If neither -l nor -r is specified, both local and remote branches will be deleted."
200+ return 0
201+ fi
202+
203+ local force_delete=false
204+ local delete_local=false
205+ local delete_remote=false
206+ local use_fzf=false
207+
208+ # Parse options to handle combined flags like -lf or -rf
209+ while [[ " $1 " == -* ]]; do
210+ case " $1 " in
211+ --fzf)
212+ use_fzf=true
213+ shift
214+ ;;
215+ -* )
216+ # Handle combined options like -lf, -rf, etc.
217+ local opt=" ${1# -} "
218+ while [[ -n " $opt " ]]; do
219+ case " ${opt: 0: 1} " in
220+ f)
221+ force_delete=true
222+ ;;
223+ l)
224+ delete_local=true
225+ ;;
226+ r)
227+ delete_remote=true
228+ ;;
229+ * )
230+ echo " Invalid option: -${opt: 0: 1} " >&2
231+ return 1
232+ ;;
233+ esac
234+ opt=" ${opt: 1} "
235+ done
236+ shift
237+ ;;
238+ esac
239+ done
240+
241+ # Default to deleting both local and remote if neither -l nor -r is specified
242+ if [ " $delete_local " = false ] && [ " $delete_remote " = false ]; then
243+ delete_local=true
244+ delete_remote=true
245+ fi
246+
247+ local branches_to_delete=()
248+
249+ if [ " $use_fzf " = true ]; then
250+ # Use fzf to select branches
251+ local branches
252+
253+ # Get the list of branches based on the specified options
254+ if [ " $delete_local " = true ]; then
255+ branches+=$( git branch --format=' %(refname:short)' 2> /dev/null) $' \n '
256+ fi
257+ if [ " $delete_remote " = true ]; then
258+ branches+=$( git branch -r --format=' %(refname:short)' 2> /dev/null) $' \n '
259+ fi
260+
261+ # Use fzf to select branches to delete
262+ branches_to_delete=($( echo " $branches " | grep -v HEAD | fzf -m --prompt=" Select branches to delete: " ) )
263+
264+ if [ ${# branches_to_delete[@]} -eq 0 ]; then
265+ echo " No branches selected for deletion."
266+ return 0
267+ fi
268+
269+ # Show selected branches and ask for confirmation
270+ echo " The following branches will be deleted:"
271+ for branch in " ${branches_to_delete[@]} " ; do
272+ echo " - $branch "
273+ done
274+ echo " "
275+
276+ local delete_type=" "
277+ if [ " $delete_local " = true ] && [ " $delete_remote " = true ]; then
278+ delete_type=" locally and remotely"
279+ elif [ " $delete_local " = true ]; then
280+ delete_type=" locally"
281+ elif [ " $delete_remote " = true ]; then
282+ delete_type=" remotely"
283+ fi
284+
285+ if [ " $force_delete " = true ]; then
286+ echo " Branches will be force deleted $delete_type ."
287+ else
288+ echo " Branches will be deleted $delete_type ."
289+ fi
290+
291+ read -p " Are you sure you want to proceed? (y/N): " -n 1 -r
292+ echo " "
293+ if [[ ! $REPLY =~ ^[Yy]$ ]]; then
294+ echo " Deletion cancelled."
295+ return 0
296+ fi
297+ else
298+ # Use command line arguments
299+ if [ $# -eq 0 ]; then
300+ echo " Usage: delete-branch [-f] [-l | -r] [--fzf] <branch-name> [<branch-name> ...]"
301+ return 1
302+ fi
303+ branches_to_delete=(" $@ " )
304+ fi
305+
306+ for branch in " ${branches_to_delete[@]} " ; do
307+ # Strip origin/ prefix from remote branch names if present
308+ local clean_branch_name=" ${branch# origin/ } "
309+
310+ if [ " $delete_local " = true ]; then
311+ if [ " $force_delete " = true ]; then
312+ # Force delete local branch
313+ git branch -D " $clean_branch_name "
314+ else
315+ # Delete local branch
316+ git branch -d " $clean_branch_name "
317+ fi
318+ fi
319+
320+ if [ " $delete_remote " = true ]; then
321+ # Check if the branch exists on the remote before attempting to delete it
322+ if git show-ref --verify --quiet refs/remotes/origin/" $clean_branch_name " ; then
323+ # Delete remote branch
324+ git push origin --delete " $clean_branch_name " --no-verify
325+ else
326+ echo " Branch '$clean_branch_name ' does not exist on the remote."
327+ fi
328+ fi
329+ done
330+ }
331+
332+ # Bash completion for delete-branch function
333+ _delete_branch_completions () {
334+ local cur prev opts branches
335+ local delete_local=false delete_remote=false
336+
337+ # Get the current word being typed
338+ cur=" ${COMP_WORDS[COMP_CWORD]} "
339+ prev=" ${COMP_WORDS[COMP_CWORD-1]} "
340+
341+ # Define available options
342+ opts=" -f -l -r --fzf -h --help"
343+
344+ # If current word starts with -, provide option completions
345+ if [[ " $cur " == -* ]]; then
346+ COMPREPLY=($( compgen -W " $opts " -- " $cur " ) )
347+ return 0
348+ fi
349+
350+ # Parse existing arguments to determine what branches to show
351+ local i
352+ for (( i= 1 ; i < COMP_CWORD; i++ )) ; do
353+ case " ${COMP_WORDS[i]} " in
354+ -l)
355+ delete_local=true
356+ ;;
357+ -r)
358+ delete_remote=true
359+ ;;
360+ --fzf)
361+ # When --fzf is used, no branch name arguments are needed
362+ return 0
363+ ;;
364+ esac
365+ done
366+
367+ # Default to both local and remote if neither -l nor -r is specified
368+ if [ " $delete_local " = false ] && [ " $delete_remote " = false ]; then
369+ delete_local=true
370+ delete_remote=true
371+ fi
372+
373+ # Build branch list based on flags
374+ branches=" "
375+ if [ " $delete_local " = true ]; then
376+ branches+=$( git branch --format=' %(refname:short)' 2> /dev/null) $' \n '
377+ fi
378+ if [ " $delete_remote " = true ]; then
379+ # Get remote branches and strip the origin/ prefix
380+ branches+=$( git branch -r --format=' %(refname:short)' 2> /dev/null | grep -v HEAD | sed ' s#^origin/##' ) $' \n '
381+ fi
382+
383+ # Provide completions for the current word
384+ COMPREPLY=($( compgen -W " $branches " -- " $cur " ) )
385+ }
386+
387+ # Register the completion function for delete-branch
388+ complete -F _delete_branch_completions delete-branch
166389
167390# `rosbag` function run through rosbridge
168391function rbag() {
0 commit comments