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 { print $"git clone '($url)'" 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 { print $"git clone execute" 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 ) }