torrent/nushell/tools/git.nu

57 lines
1.4 KiB
Plaintext
Raw Normal View History

2024-01-13 10:01:54 +00:00
def gitcheck [] {
let $email = ^git config user.email
# Check if Git email is set
if ( $email | str stats | get words) < 2 {
print "Git email is not set!"
let $email = input "Enter your Git email: "
# Set the Git email
^git config --global user.email "$git_email"
echo "Git email set to '$git_email'."
}
}
export def git_configure [] {
gitcheck
mkdir ~/.ssh
let $nr_known_hosts = ^grep github.com ~/.ssh/known_hosts | str stats| get lines
# Check if Git email is set
if $nr_known_hosts < 1 {n
ssh-keyscan github.com >> ~/.ssh/known_hosts
git config --global pull.rebase false
}
}
export def git_clone [ name: string url: string , --reset=false , --pull=false ] string {
2024-01-13 10:37:40 +00:00
print $"git clone '($url)'"
2024-01-13 10:01:54 +00:00
git_configure
let $dest = $"($env.BASE)/code/($name)"
if $reset {
print $"remove git dir: ($dest)"
rm -f $dest
}
if ($dest | path exists) and ( ( ls $dest | length ) > 0 ) {
mkdir $dest
cd $dest
if $pull == true {
print $"git pull for ($url)"
git pull
}
} else {
2024-01-13 10:37:40 +00:00
print $"git clone execute"
2024-01-13 10:01:54 +00:00
cd $"($env.BASE)/code"
git clone --depth 1 --no-single-branch $url
}
# git checkout $CLBRANCH
return $dest
}
def sshagent_loaded [ ] bool {
return ( (ssh-add -l | lines -s | length) > 0 )
}