fish: add clone function
This commit is contained in:
parent
2cc1a1672b
commit
59b78472ba
24
.config/fish/functions/clone.fish
Normal file
24
.config/fish/functions/clone.fish
Normal file
@ -0,0 +1,24 @@
|
||||
function clone --argument-names giturl
|
||||
# These regular expressions are far from comprehensive, but they work for me.
|
||||
#
|
||||
# Examples:
|
||||
# https://github.com/NixOS/nix
|
||||
# https://git.sr.ht/~sircmpwn/git.sr.ht
|
||||
# git@git.sr.ht:~crg/home
|
||||
# ssh://git@gitlab.haskell.org:ghc/ghc.git
|
||||
#
|
||||
set --local giturl_format1 '^https:\/\/(?<githost>[^\/]+)\/(?<gituser>[^\/]+)\/(?<gitrepo>.+)$'
|
||||
set --local giturl_format2 '^(ssh:\/\/)?[a-z]+?@(?<githost>[^:]+):([0-9]+\/)?(?<gituser>[^\/]+)\/(?<gitrepo>.+)$'
|
||||
|
||||
string match -rq $giturl_format1 $giturl; or string match -rq $giturl_format2 $giturl
|
||||
|
||||
set gituser (string replace '~' '' $gituser)
|
||||
set gitrepo (string replace -r '.git$' '' $gitrepo)
|
||||
|
||||
set --local gitdir "$HOME/Code/$githost/$gituser/$gitrepo"
|
||||
|
||||
if confirm "Clone to $gitdir?"
|
||||
git clone $giturl "$gitdir"
|
||||
cd "$gitdir"
|
||||
end
|
||||
end
|
@ -1,6 +1,6 @@
|
||||
function confirm --description "Ask for user confirmation"
|
||||
function confirm --description "Ask for user confirmation" --argument-names prompt
|
||||
while true
|
||||
read --local --prompt-str='Are you sure you want to continue? [y/N] ' confirmed
|
||||
read --local --prompt-str="$prompt [y/N] " confirmed
|
||||
|
||||
switch $confirmed
|
||||
case Y y
|
||||
|
@ -23,7 +23,7 @@ function nix_upgrade --description "Upgrade nix packages"
|
||||
test -z "$nix_pkgs_rem" || echo "Removed packages: $nix_pkgs_rem"
|
||||
|
||||
# Step 3: Confirm changes
|
||||
if confirm
|
||||
if confirm "Continue with upgrade?"
|
||||
nix-env -irf "$nix_pkgs_filepath"
|
||||
end
|
||||
end
|
||||
|
@ -5,7 +5,7 @@ function npm_upgrade --description "Upgrade npm packages"
|
||||
echo "All packages up-to-date."
|
||||
else
|
||||
echo "Outdated packages: $npm_pkgs_outdated"
|
||||
if confirm
|
||||
if confirm "Continue with upgrade?"
|
||||
npm update -g
|
||||
end
|
||||
end
|
||||
|
@ -5,7 +5,7 @@ function pip_upgrade --description "Upgrade python packages"
|
||||
echo "All packages up-to-date."
|
||||
else
|
||||
echo "Outdated packages: $py_pkgs_outdated"
|
||||
if confirm
|
||||
if confirm "Continue with upgrade?"
|
||||
for py_pkg in $py_pkgs_outdated
|
||||
python3 -m pip install -U $py_pkg
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user