fish
This commit is contained in:
commit
4bb0691c2c
21
completions/repo.fish
Normal file
21
completions/repo.fish
Normal file
@ -0,0 +1,21 @@
|
||||
function __repo_commands
|
||||
echo "get\tClone a repository"
|
||||
echo "open\tOpen the repository in a browser"
|
||||
echo "aur\tClone an AUR repository"
|
||||
echo "list\tList all repositories"
|
||||
echo "go\tNavigate to a repository"
|
||||
echo "goto\tNavigate to a repository"
|
||||
echo "new\tCreate a new repository"
|
||||
echo "create\tCreate a new repository"
|
||||
echo "help\tShow help message"
|
||||
end
|
||||
|
||||
function __repo_needs_command
|
||||
set -l cmd (commandline -opc)
|
||||
if test (count $cmd) -eq 1
|
||||
return 0
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
complete -f -c repo -n __repo_needs_command -a '(__repo_commands)'
|
16
functions/_repo_clean_path.fish
Normal file
16
functions/_repo_clean_path.fish
Normal file
@ -0,0 +1,16 @@
|
||||
function _repo_clean_path
|
||||
set stripped $argv[1]
|
||||
|
||||
for prefix in "http://" "https://" "git@" "ssh://" "aur@"
|
||||
if string match -q "$prefix*" $stripped
|
||||
set stripped (string replace -r "^$prefix" "" $stripped)
|
||||
end
|
||||
end
|
||||
|
||||
set stripped (echo $stripped | sed -e "s/:/\//1")
|
||||
|
||||
if not string match -q "*/*" $stripped
|
||||
set stripped "github.com/$stripped"
|
||||
end
|
||||
echo $stripped
|
||||
end
|
24
functions/_repo_clone.fish
Normal file
24
functions/_repo_clone.fish
Normal file
@ -0,0 +1,24 @@
|
||||
function _repo_clone
|
||||
if test -z "$argv[2]"
|
||||
echo "Error: Repository path is required"
|
||||
return 1
|
||||
end
|
||||
|
||||
set repo_prefix $argv[1]
|
||||
set cleaned (_repo_clean_path $argv[2])
|
||||
set output_path "$REPO_BASE_DIR/$cleaned"
|
||||
# Remove .git suffix if present
|
||||
set trimmed (string replace -r '(\.git)$' '' "$output_path")
|
||||
|
||||
mkdir -p "$trimmed"
|
||||
|
||||
if not test -d "$trimmed/.git"
|
||||
set repourl (echo "$repo_prefix@$cleaned" | sed -e "s/\//:/1")
|
||||
echo "Cloning $repourl to $trimmed..."
|
||||
git clone "$repourl" "$trimmed"
|
||||
else
|
||||
echo "Repository already exists: $trimmed"
|
||||
end
|
||||
|
||||
_repo_post_clone "$trimmed"
|
||||
end
|
12
functions/_repo_goto.fish
Normal file
12
functions/_repo_goto.fish
Normal file
@ -0,0 +1,12 @@
|
||||
function _repo_goto
|
||||
if test -z "$argv[1]"
|
||||
echo "Error: Repository path is required"
|
||||
return 1
|
||||
end
|
||||
|
||||
set cleaned (_repo_clean_path $argv[1])
|
||||
set output_path "$REPO_BASE_DIR/$cleaned"
|
||||
# Remove .git suffix if present
|
||||
set trimmed (string replace -r '(\.git)$' '' "$output_path")
|
||||
_repo_post_goto $trimmed
|
||||
end
|
17
functions/_repo_help.fish
Normal file
17
functions/_repo_help.fish
Normal file
@ -0,0 +1,17 @@
|
||||
function _repo_help
|
||||
cat < < EOF
|
||||
Usage: repo <command > < repository >
|
||||
Commands:
|
||||
get Clone a repository to the repos directory
|
||||
open Open the current repository in the browser
|
||||
aur Clone an AUR repository
|
||||
list List all repositories
|
||||
go | goto Navigate to a repository
|
||||
new | create Create a new repository
|
||||
help Show this help message
|
||||
|
||||
Examples:
|
||||
repo get github.com/user/repo
|
||||
repo open
|
||||
EOF
|
||||
end
|
6
functions/_repo_list.fish
Normal file
6
functions/_repo_list.fish
Normal file
@ -0,0 +1,6 @@
|
||||
function _repo_list
|
||||
for git_dir in (find "$REPO_BASE_DIR" -type d -name ".git")
|
||||
set parent_dir (dirname "$git_dir")
|
||||
echo (basename "$parent_dir" | sed 's/\./_/g')
|
||||
end
|
||||
end
|
20
functions/_repo_new.fish
Normal file
20
functions/_repo_new.fish
Normal file
@ -0,0 +1,20 @@
|
||||
function _repo_new
|
||||
if test -z "$argv[1]"
|
||||
echo "Error: Repository path is required"
|
||||
return 1
|
||||
end
|
||||
|
||||
set cleaned (_repo_clean_path $argv[1])
|
||||
set output_path "$REPO_BASE_DIR/$cleaned"
|
||||
# Remove .git suffix if present
|
||||
set trimmed (string replace -r '(\.git)$' '' "$output_path")
|
||||
mkdir -p "$trimmed"
|
||||
|
||||
if not test -d "$trimmed/.git"
|
||||
git init "$trimmed"
|
||||
else
|
||||
echo "Repository already exists: $trimmed"
|
||||
end
|
||||
|
||||
_repo_post_new "$trimmed"
|
||||
end
|
6
functions/_repo_open.fish
Normal file
6
functions/_repo_open.fish
Normal file
@ -0,0 +1,6 @@
|
||||
function _repo_open
|
||||
set remote (git remote get-url origin)
|
||||
set remote (string replace -r "git@" "https://" $remote)
|
||||
set remote (string replace --max=1 ":" "/" $remote)
|
||||
xdg-open "$remote"
|
||||
end
|
7
functions/_repo_post_clone.fish
Normal file
7
functions/_repo_post_clone.fish
Normal file
@ -0,0 +1,7 @@
|
||||
function _repo_post_clone
|
||||
if functions -q repo_post_clone
|
||||
repo_post_clone $argv[1]
|
||||
else
|
||||
cd $argv[1]
|
||||
end
|
||||
end
|
7
functions/_repo_post_goto.fish
Normal file
7
functions/_repo_post_goto.fish
Normal file
@ -0,0 +1,7 @@
|
||||
function repo_post_goto
|
||||
if functions -q repo_post_goto
|
||||
repo_post_goto $argv[1]
|
||||
else
|
||||
cd $argv[1]
|
||||
end
|
||||
end
|
7
functions/_repo_post_new.fish
Normal file
7
functions/_repo_post_new.fish
Normal file
@ -0,0 +1,7 @@
|
||||
function _repo_post_new
|
||||
if functions -q repo_post_new
|
||||
repo_post_new $argv
|
||||
else
|
||||
cd $argv[1]
|
||||
end
|
||||
end
|
25
functions/repo.fish
Normal file
25
functions/repo.fish
Normal file
@ -0,0 +1,25 @@
|
||||
function repo
|
||||
set cmd $argv[1]
|
||||
set arg $argv[2]
|
||||
|
||||
switch $cmd
|
||||
case get
|
||||
_repo_clone git $arg
|
||||
case aur
|
||||
_repo_clone aur $arg
|
||||
case open
|
||||
_repo_open
|
||||
case list
|
||||
_repo_list
|
||||
case go goto
|
||||
_repo_goto $arg
|
||||
case new create
|
||||
_repo_new $arg
|
||||
case help -h -help --help
|
||||
_repo_help
|
||||
case '*'
|
||||
echo "Unknown command: $cmd"
|
||||
_repo_help
|
||||
return 1
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user