-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.functions
More file actions
92 lines (76 loc) · 1.82 KB
/
.functions
File metadata and controls
92 lines (76 loc) · 1.82 KB
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
#!/usr/bin/env bash
# Test function
function t() {
if [[ "$PWD" == "$HOME" ]]; then
cd ~/Tests || exit
elif [[ -r "package.json" ]]; then
npm test "$@"
elif [[ -r "go.mod" ]]; then
go test "$@"
elif [[ -r "Gemfile" ]]; then
rake test "$@"
else
echo "test command"
fi
}
# Git clone function
function gclone() {
if ! command -v gh &>/dev/null; then
echo "gh command not found"
exit
fi
repo=$1
repo=${repo/#https:\/\/github.com\//}
dir=$2
if [[ -z $dir ]]; then
dir=${repo/\//@}
fi
gh repo clone $repo $dir
}
# Example: feature-YYYYmmdd-name
function git-feature() {
date_format=$(date -u +"%Y%m%d")
branch="feature-$date_format-$1"
git checkout -b "$branch"
}
# Open browser goto repo home page by origin remote
function git-home() {
url=$(git config remote.origin.url)
open "$url"
}
# refs https://github.com/yuler/gh-todo
function gh-todo() {
gh todo "$@"
}
# refs: https://gist.github.com/dhh/18575558fc5ee10f15b6cd3e108ed844
# Create a new worktree and branch from within current git directory.
gwa() {
if [[ -z "$1" ]]; then
echo "Usage: gwa [branch name]"
return
# exit 1
fi
local branch="$1"
local base="$(basename "$PWD")"
local path="../${base}--${branch}"
git worktree add -b "$branch" "$path"
mise trust "$path"
cd "$path"
}
# Remove worktree and branch from within active worktree directory.
gwd() {
if gum confirm "Remove worktree and branch?"; then
local cwd base branch root
cwd="$(pwd)"
worktree="$(basename "$cwd")"
# split on first `--`
root="${worktree%%--*}"
branch="${worktree#*--}"
# Protect against accidentially nuking a non-worktree directory
if [[ "$root" != "$worktree" ]]; then
cd "../$root"
git worktree remove "$worktree" --force
git branch -D "$branch"
fi
fi
}