Skip to content

Commit fc3a763

Browse files
Merge pull request #18 from LangLangBart/limit
new flag to limit results
2 parents dd35856 + 1a24d11 commit fc3a763

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,25 @@ gh s [search] [flag]
5252
```
5353
takes one of the following arguments or flags
5454

55-
| flags | description | multiple | example
56-
|:------------ |:------------------------------------------------ |:---------- |:--------
57-
| -E, --empty | do not prompt for name, search by flags only | no | gh s -E -l go -l rust
58-
| -l, --lang | narrow down the search to a specific language | yes (OR) | gh s prompt -l go -l lua
59-
| -d, --desc | search for keyword in the repository description | no | gh s neovim -d plugin
60-
| -u, --user | restrict the search to a specific user | no | gh s lsp -u neovim
61-
| -t, --topic | narrow down the search to specific topics | yes (AND) | gh s lsp -t plugin -t neovim
62-
| -c, --colour | change colour of the prompt | no | gh s nvim -c magenta
63-
| -h, --help | show the help page | no | gh s -h
64-
| -V, --version| print the current version | no | gh s -V
55+
| flags | description | multiple | example |
56+
| :------------ | :----------------------------------------------- | :-------- | :--------------------------- |
57+
| -E, --empty | do not prompt for name, search by flags only | no | gh s -E -l go -l rust |
58+
| -l, --lang | narrow down the search to a specific language | yes (OR) | gh s prompt -l go -l lua |
59+
| -d, --desc | search for keyword in the repository description | no | gh s neovim -d plugin |
60+
| -u, --user | restrict the search to a specific user | no | gh s lsp -u neovim |
61+
| -t, --topic | narrow down the search to specific topics | yes (AND) | gh s lsp -t plugin -t neovim |
62+
| -c, --colour | change colour of the prompt | no | gh s nvim -c magenta |
63+
| -L, --limit | limit the number of results (default 20) | no | gh s nvim -L 3 |
64+
| -h, --help | show the help page | no | gh s -h |
65+
| -V, --version | print the current version | no | gh s -V |
6566

6667
The prompt accepts the following navigation commands:
6768

68-
| key | description
69-
|:------------- |:-----------------------------------
70-
| arrow keys | browse results list
71-
| `/` | toggle search in results list
72-
| `enter (<CR>)`| print selected repository URL to `stdout`
69+
| key | description |
70+
| :------------- | :---------------------------------------- |
71+
| arrow keys | browse results list |
72+
| `/` | toggle search in results list |
73+
| `enter (<CR>)` | print selected repository URL to `stdout` |
7374

7475
### Search by topic or language only
7576
`gh-s` allows to skip prompting for a repository name by passing the `-E` flag; this in turn implies that the query searches against all possible GitHub repositories, which may result in longer response times. Notice furthermore that `-E` must always be accompanied by at least another non-empty flag. Use with care, however it does allow for some interesting statistics or general curiosity: check the [Wiki](https://github.com/gennaro-tedesco/gh-s/wiki/Common-queries)!

cmd/root.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var rootCmd = &cobra.Command{
2828
user, _ := cmd.Flags().GetString("user")
2929
topicList, _ := cmd.Flags().GetStringSlice("topic")
3030
colour, _ := cmd.Flags().GetString("colour")
31+
limit, _ := cmd.Flags().GetInt("limit")
3132

3233
searchString := func() string {
3334
if empty, _ := (cmd.Flags().GetBool("empty")); empty {
@@ -45,7 +46,7 @@ var rootCmd = &cobra.Command{
4546
fmt.Println("\033[31m ✘\033[0m No results found")
4647
os.Exit(1)
4748
}
48-
PromptList := getSelectionPrompt(repos, colour)
49+
PromptList := getSelectionPrompt(repos, colour, limit)
4950

5051
idx, _, err := PromptList.Run()
5152
if err != nil {
@@ -68,6 +69,7 @@ func init() {
6869
rootCmd.Flags().StringP("user", "u", "", "search repository by user")
6970
rootCmd.Flags().StringSliceVarP(&topics, "topic", "t", []string{}, "search repository by topic")
7071
rootCmd.Flags().StringP("colour", "c", "cyan", "colour of selection prompt")
72+
rootCmd.Flags().IntP("limit", "L", 20, "limit the number of results (default 20)")
7173
rootCmd.Flags().BoolP("empty", "E", false, "allow for empty name search")
7274
rootCmd.Flags().BoolP("version", "V", false, "print current version")
7375
rootCmd.SetHelpTemplate(getRootHelp())
@@ -126,6 +128,7 @@ Flags:
126128
multiple topics can be specified:
127129
-t go -t gh-extension
128130
-c, --colour change prompt colour
131+
-L, --limit limit the number of results (default 20)
129132
-V, --version print current version
130133
-h, --help show this help page
131134

cmd/ui.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ func getTemplate(colour string) *promptui.SelectTemplates {
8585

8686
}
8787

88-
func getSelectionPrompt(repos []repoInfo, colour string) *promptui.Select {
88+
func getSelectionPrompt(repos []repoInfo, colour string, limit int) *promptui.Select {
8989
return &promptui.Select{
9090
Stdout: os.Stderr,
9191
Stdin: os.Stdin,
9292
Label: "repository list",
9393
Items: repos,
9494
Templates: getTemplate(colour),
95-
Size: 20,
95+
Size: limit,
9696
Searcher: func(input string, idx int) bool {
9797
repo := repos[idx]
9898
title := strings.ToLower(repo.Name)

0 commit comments

Comments
 (0)