From 75d6b235bf8c70ea63aed19c16bef323abf9e0db Mon Sep 17 00:00:00 2001 From: jffiorillo Date: Wed, 16 Oct 2019 11:56:02 +0200 Subject: [PATCH 1/2] Update gh.fish Fix print issue with python 3.6.5 --- config/fish/functions/gh.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/fish/functions/gh.fish b/config/fish/functions/gh.fish index 6e35749..4ef2313 100644 --- a/config/fish/functions/gh.fish +++ b/config/fish/functions/gh.fish @@ -9,7 +9,7 @@ end # Prints the origin and remote # Example: oguzbilgic/dotfiles function org_repo - echo (origin | python -c "import sys; url = sys.stdin.readlines()[0].strip(); print url.split(':')[1][:-4]") + echo (origin | python -c "import sys; url = sys.stdin.readlines()[0].strip(); print(url.split(':')[1][:-4)]") end # Prints the current branch name From 106b46881503d59d7128a962544bd5750f4583a5 Mon Sep 17 00:00:00 2001 From: jffiorillo Date: Fri, 18 Oct 2019 15:38:33 +0200 Subject: [PATCH 2/2] Update gh.fish Removed python dependency. Using argparse to parse argument in gh function. --- config/fish/functions/gh.fish | 74 +++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 17 deletions(-) diff --git a/config/fish/functions/gh.fish b/config/fish/functions/gh.fish index 4ef2313..4d105bb 100644 --- a/config/fish/functions/gh.fish +++ b/config/fish/functions/gh.fish @@ -9,7 +9,9 @@ end # Prints the origin and remote # Example: oguzbilgic/dotfiles function org_repo - echo (origin | python -c "import sys; url = sys.stdin.readlines()[0].strip(); print(url.split(':')[1][:-4)]") + set --local origin_with_dot_git (string split ":" (git_origin)) + set --local org_repo (string split "." $origin_with_dot_git[2]) + echo $org_repo[1] end # Prints the current branch name @@ -36,21 +38,59 @@ end # gh commit opens the last commit of the current branch # gh commits opens the commits page for the current branch function gh - if test (count $argv) -lt 1 - open "https://github.com/"(org_repo)"/tree/"(branch) - else if test -f $argv[1] - open "https://github.com/"(org_repo)"/blob/"(commit)"/"(echo $argv[1]) - else if test $argv[1] = "issues" - open "https://github.com/"(org_repo)"/issues" - else if test $argv[1] = "pulls" - open "https://github.com/"(org_repo)"/issues" - else if test $argv[1] = "actions" - open "https://github.com/"(org_repo)"/issues" - else if test $argv[1] = "compare" - open "https://github.com/"(org_repo)"/compare/"(branch) - else if test $argv[1] = "commits" - open "https://github.com/"(org_repo)"/commits/"(branch) - else if test $argv[1] = "commit" - open "https://github.com/"(org_repo)"/commit/"(commit) + #Options for the argparse + set --local options 'h/help' 'f/file=' 'i/issue=!_validate_int --min 1' 'b/issues' 'u/pulls' 'p/pull=!_validate_int --min 1' 'a/actions' 'o/compare' 'c/commit' 's/commits' 'd' + + # Read the arguments of the function and validates according to $options + argparse $options -- $argv + + if set --query _flag_h + echo "Usage: gh [-h/help ] [-f/file [file] ] [-i/issue [issue number] ] [-b/issues] [-u/pulls] [-p/pull [pull number] ] [-a/actions] [-o/compare] [-c/commit] [-s/commits] [-d]" + echo "Options:" + echo_tabulated ". -f/file [file_name] Open the first file matching [file_name]" + echo_tabulated ". -i/issue [issue number] Open the [issue_number]." + echo_tabulated ". -b/issues Open issues list" + echo_tabulated ". -u/pulls Open the pull requests list" + echo_tabulated ". -p/pull [pull number] Open the pull request [pull_number]" + echo_tabulated ". -a/actions Open the actions" + echo_tabulated ". -o/compare Open the compare view" + echo_tabulated ". -c/commit Open the last commit" + echo_tabulated ". -s/commits Open the commits list" + echo_tabulated ". -d Open the current branch" + return 0 + end + + if set --query _flag_f + set file_path (find . -name "*$_flag_f*") + set file_path $file_path[1] + if not set --query file_path + echo_error "File $_flag_f not found." + return 1 + end + set url "https://github.com/"(git_org_repo)"/blob/"(git_branch)"/$file_path" + else if set --query _flag_i + set url "https://github.com/"(git_org_repo)"/issue/$_flag_i" + else if set --query _flag_a + set url "https://github.com/"(git_org_repo)"/issues" + else if set --query _flag_u + set url "https://github.com/"(git_org_repo)"/pulls" + else if set --query _flag_p + set url "https://github.com/"(git_org_repo)"/pull/$_flag_p" + else if set --query _flag_a + set url "https://github.com/"(git_org_repo)"/actions" + else if set --query _flag_o + set url "https://github.com/"(git_org_repo)"/compare/"(git_branch) + else if set --query _flag_c + set url "https://github.com/"(git_org_repo)"/commit/"(git_commit) + else if set --query _flag_s + set url "https://github.com/"(git_org_repo)"/commits/"(git_branch) + else if set --query _flag_m + set url "https://github.com/"(git_org_repo)"/tree/"(git_branch) + end + if set --query url + open $url + else + echo_error "No valid argument provided." end + return 0 end