gh
and fzf
locally, or even install them in the terminal of a dev space in the SAP Business Application Studio to try things out. See how we do this in the SAP TechEd 2020 Developer Keynote repository - take a look specifically at the Add tools to your dev space section.gh
for the first time, you'll need to authenticate - use gh auth login
and follow the prompts. Then you're all set to use the org-sampler
script as shown above. 1 #!/usr/bin/env bash
2
3 readonly org="${1:?Specify org name}"
4
5 jqscript() {
6
7 cat << EOF
8 .[]
9 | [
10 .name,
11 "Name: \(.name)\n\nDescription: \(.description)\n\nLanguage: \(.language)\nWatchers: \(.watchers_count)\nStars: \(.stargazers_count)\nForks: \(.forks_count)"
12 ]
13 | @tsv
14 EOF
15
16 }
17
18 gh api \
19 "/orgs/$org/repos" \
20 --paginate \
21 --cache 1h \
22 --jq "$(jqscript)" \
23 | fzf \
24 --with-nth=1 \
25 --delimiter='\t' \
26 --preview='echo -e {2}' \
27 --preview-window=up:sharp:wrap:40%
env
to find bash
on my system to execute the contents of the filejq
script that will be passed to the invocation of gh
to parse the JSON output that is returned from the API call.[]
to say "take each of the array items"; each array item represents a repository within the organisation, and has different properties|
) into a list of fields that we keep together with [
starting on this line, and ending with ]
on line 12name
property (the name of the repository)\n
); this string is what's to be shown in the preview (at the top, in the demo above)@tsv
which produces a tab separated values set of recordsgh
's api
facility$org
) specified when the script was invoked--paginate
option tells gh
to make enough calls to page through all of the results - very convenient!--cache
option allows for cacheing of the results, to save on hitting the API endpoints too frequently and unnecessarily; it makes a lot of sense here given the frequency of new repository creations--jq
option is also recent, and given that the API output is JSON, is very useful; we use the jq
script defined earlier in the jqscript
function here to produce that set of tab separated records (where the first field is the repository name and the second field is the multi-line string showing the repository details)fzf
to give us a chance to browse or search through the entire list and see the repositories' details--with-nth=1
we can tell fzf
to only show the first field in the actual selection listfzf
how to know what the fields are with --delimiter='\t'
, i.e. the fields are separated by tab characters--preview='echo -e {2}'
we tell fzf
that we want to have something shown in a preview window for each item; what is shown is the result of echo -e {2}
where {2}
is an fzf
placeholder representing the second field in the list (i.e. the multi-line string) and the -e
switch tells echo
to actually interpret backslash escapes, meaning that the newline characters (\n
) in the field will be rendered properly and the preview will indeed be multi-line--preview-window=up:sharp:wrap:40%
option tells fzf
how to display the preview window, including that it should be at the top, above the list (up
), that any long text lines should be wrapped (this is good for the value of the repositories' description fields) and that the preview window should take up just less than half of the screen (40%
)You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
12 | |
10 | |
9 | |
7 | |
7 | |
7 | |
6 | |
6 | |
5 | |
4 |