This repository has been archived by the owner on Jun 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repo.nu
103 lines (86 loc) · 2.41 KB
/
repo.nu
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
#*
#* _ __ _ _
#* __ _ ___ __ _| |_ / _(_) |___ ___ WEBSITE: https://goatfiles.github.io
#* / _` / _ \/ _` | _| _| | / -_|_-< REPOS: https://github.com/goatfiles
#* \__, \___/\__,_|\__|_| |_|_\___/__/ LICENCE: https://github.com/goatfiles/dotfiles/blob/main/LICENSE
#* |___/
#* MAINTAINERS:
#* AMTOINE: https://github.com/amtoine antoine#1306 7C5EE50BA27B86B7F9D5A7BA37AAE9B486CFF1AB
#* ATXR: https://github.com/atxr atxr#6214 3B25AF716B608D41AB86C3D20E55E4B1DE5B2C8B
#*
use scripts/prompt.nu
alias FZF_PICK_PREVIEW = "
path=$(ghq root)/$(echo {} | sed 's/: /.com\\//')
echo "TREE:"
git -C $path --no-pager log --graph --branches --remotes --tags --oneline --decorate --simplify-by-decoration -n 10 --color=always
echo ""
echo "STATUS:"
git -C $path --no-pager status --short
echo ""
echo "STASHES:"
git -C $path --no-pager stash list
echo ""
echo "FILES:"
ls -la --color=always $path | awk '{print $1,$9}'
"
# TODO
def pick_repo [
prompt: string
] {
let choice = (
ghq list |
lines |
str replace ".com/" ": " |
sort --ignore-case |
prompt fzf_ask $prompt (FZF_PICK_PREVIEW) |
str replace ": " ".com/"
)
$choice
}
# TODO
export def-env goto [
--clear (-c): bool # TODO
] {
# jump to any repo registered with ghq.
#
# the function will:
# - (1) do nothing and abort when selecting no repo.
# - (2) jump to the selected repo and print the content of the repo.
#
# dependencies:
# - ghq
# - fzf
#
let choice = (pick_repo "Please choose a repo to jump to: ")
# compute the directory to jump to.
let path = (
ghq root
| str trim
| path join $choice
)
cd $path
if ($clear) {
clear
}
}
# TODO
export def pull [
owner: string = $"(git config --get user.name | str trim)"
] {
let choice = (
gh repo list $owner --json name |
from json |
get name |
sort --ignore-case |
uniq |
prompt fzf_ask $"Please choose a repo to pull from https://github.com/($owner): "
)
let repository = ([$owner $choice] | str collect "/")
ghq get -p $repository
}
# TODO
export def remove [] {
let repo = (pick_repo "Please choose a repo to remove: ")
let path = ($env.GHQ_ROOT | path join $repo)
rm --trash --interactive --recursive $path
}