stuff
This commit is contained in:
parent
e180b13f74
commit
7ff0cd043a
@ -18,4 +18,25 @@ function __repo_needs_command
|
|||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function __repo_using_command
|
||||||
|
set -l cmd (commandline -opc)
|
||||||
|
if test (count $cmd) -gt 1
|
||||||
|
if test $argv[1] = $cmd[2]
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
function __repo_list_repos
|
||||||
|
find "$REPO_BASE_DIR" -type d -name ".git" | path dirname | sort | path basename
|
||||||
|
end
|
||||||
|
|
||||||
|
# Main command completions
|
||||||
complete -f -c repo -n __repo_needs_command -a '(__repo_commands)'
|
complete -f -c repo -n __repo_needs_command -a '(__repo_commands)'
|
||||||
|
|
||||||
|
# Repository completions
|
||||||
|
complete -f -c repo -n '__repo_using_command go; or __repo_using_command goto' -a '(__repo_list_repos)'
|
||||||
|
|
||||||
|
# Help option
|
||||||
|
complete -f -c repo -s h -l help -d 'Show help message'
|
||||||
|
@ -7,7 +7,7 @@ function _repo_clean_path
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
set stripped (echo $stripped | sed -e "s/:/\//1")
|
set stripped (string replace --max=1 ":" "/" $stripped)
|
||||||
|
|
||||||
if not string match -q "*/*" $stripped
|
if not string match -q "*/*" $stripped
|
||||||
set stripped "github.com/$stripped"
|
set stripped "github.com/$stripped"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
function _repo_clone
|
function _repo_clone
|
||||||
if test -z "$argv[2]"
|
if not set -q argv[2]; or test -z "$argv[2]"
|
||||||
echo "Error: Repository path is required"
|
echo "Error: Repository path is required"
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
@ -13,7 +13,7 @@ function _repo_clone
|
|||||||
mkdir -p "$trimmed"
|
mkdir -p "$trimmed"
|
||||||
|
|
||||||
if not test -d "$trimmed/.git"
|
if not test -d "$trimmed/.git"
|
||||||
set repourl (echo "$repo_prefix@$cleaned" | sed -e "s/\//:/1")
|
set repourl (string replace --max=1 "/" ":" "$repo_prefix@$cleaned")
|
||||||
echo "Cloning $repourl to $trimmed..."
|
echo "Cloning $repourl to $trimmed..."
|
||||||
git clone "$repourl" "$trimmed"
|
git clone "$repourl" "$trimmed"
|
||||||
else
|
else
|
||||||
@ -21,4 +21,4 @@ function _repo_clone
|
|||||||
end
|
end
|
||||||
|
|
||||||
_repo_post_clone "$trimmed"
|
_repo_post_clone "$trimmed"
|
||||||
end
|
end
|
@ -1,5 +1,5 @@
|
|||||||
function _repo_goto
|
function _repo_goto
|
||||||
if test -z "$argv[1]"
|
if not set -q argv[1]; or test -z "$argv[1]"
|
||||||
echo "Error: Repository path is required"
|
echo "Error: Repository path is required"
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
@ -9,4 +9,4 @@ function _repo_goto
|
|||||||
# Remove .git suffix if present
|
# Remove .git suffix if present
|
||||||
set trimmed (string replace -r '(\.git)$' '' "$output_path")
|
set trimmed (string replace -r '(\.git)$' '' "$output_path")
|
||||||
_repo_post_goto $trimmed
|
_repo_post_goto $trimmed
|
||||||
end
|
end
|
@ -1,6 +1,6 @@
|
|||||||
function _repo_list
|
function _repo_list
|
||||||
for git_dir in (find "$REPO_BASE_DIR" -type d -name ".git")
|
for git_dir in (find "$REPO_BASE_DIR" -type d -name ".git")
|
||||||
set parent_dir (dirname "$git_dir")
|
set parent_dir (path dirname "$git_dir")
|
||||||
echo (basename "$parent_dir" | sed 's/\./_/g')
|
echo (path basename "$parent_dir" | string replace -a "." "_")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
function _repo_new
|
function _repo_new
|
||||||
if test -z "$argv[1]"
|
if not set -q argv[1]; or test -z "$argv[1]"
|
||||||
echo "Error: Repository path is required"
|
echo "Error: Repository path is required"
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
@ -17,4 +17,4 @@ function _repo_new
|
|||||||
end
|
end
|
||||||
|
|
||||||
_repo_post_new "$trimmed"
|
_repo_post_new "$trimmed"
|
||||||
end
|
end
|
@ -2,5 +2,14 @@ function _repo_open
|
|||||||
set remote (git remote get-url origin)
|
set remote (git remote get-url origin)
|
||||||
set remote (string replace -r "git@" "https://" $remote)
|
set remote (string replace -r "git@" "https://" $remote)
|
||||||
set remote (string replace --max=1 ":" "/" $remote)
|
set remote (string replace --max=1 ":" "/" $remote)
|
||||||
xdg-open "$remote"
|
|
||||||
|
if not command -q xdg-open
|
||||||
|
echo "Error: xdg-open command not found"
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if not xdg-open "$remote" 2>/dev/null
|
||||||
|
echo "Error: Failed to open $remote"
|
||||||
|
return 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
function repo_post_goto
|
function _repo_post_goto
|
||||||
if functions -q repo_post_goto
|
if functions -q repo_post_goto
|
||||||
repo_post_goto $argv[1]
|
repo_post_goto $argv[1]
|
||||||
else
|
else
|
||||||
|
@ -1,6 +1,22 @@
|
|||||||
function repo
|
function repo
|
||||||
set cmd $argv[1]
|
argparse h/help -- $argv
|
||||||
set arg $argv[2]
|
or begin
|
||||||
|
_repo_help
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if set -q _flag_help
|
||||||
|
_repo_help
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
if not set -q argv[1]
|
||||||
|
_repo_help
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
set -l cmd $argv[1]
|
||||||
|
set -l arg $argv[2]
|
||||||
|
|
||||||
switch $cmd
|
switch $cmd
|
||||||
case get
|
case get
|
||||||
@ -15,8 +31,6 @@ function repo
|
|||||||
_repo_goto $arg
|
_repo_goto $arg
|
||||||
case new create
|
case new create
|
||||||
_repo_new $arg
|
_repo_new $arg
|
||||||
case help -h -help --help
|
|
||||||
_repo_help
|
|
||||||
case '*'
|
case '*'
|
||||||
echo "Unknown command: $cmd"
|
echo "Unknown command: $cmd"
|
||||||
_repo_help
|
_repo_help
|
||||||
|
Loading…
x
Reference in New Issue
Block a user