mirror of
https://github.com/sadan4/dotfiles.git
synced 2025-06-07 13:03:03 -04:00
add clone repo commannd
This commit is contained in:
parent
68309aa023
commit
99714482de
2 changed files with 123 additions and 4 deletions
84
common/users/homeModules/scripts/cloneRepoImpl.sh
Normal file
84
common/users/homeModules/scripts/cloneRepoImpl.sh
Normal file
|
@ -0,0 +1,84 @@
|
|||
set -e
|
||||
echoe() {
|
||||
echo $* 1>&2
|
||||
}
|
||||
|
||||
getTotalRepoCount() {
|
||||
echo $(gh api user -q ".total_private_repos + .public_repos")
|
||||
}
|
||||
|
||||
showGuiAndPickRepo() {
|
||||
local totalRepos
|
||||
totalRepos=$(getTotalRepoCount)
|
||||
if [[ $? -ne 0 ]]; then return 1; fi
|
||||
local pick
|
||||
pick=$(gh repo list -L ${totalRepos} --json nameWithOwner -q ".[] | .nameWithOwner" | fzf \
|
||||
--scheme path \
|
||||
--cycle \
|
||||
--filepath-word \
|
||||
--height 50% \
|
||||
--reverse \
|
||||
--border \
|
||||
--border-label " Select Repo To Clone " \
|
||||
--color label:bold:cyan \
|
||||
--tiebreak index
|
||||
)
|
||||
if [[ $? -ne 0 ]]; then return 1; fi
|
||||
echo ${pick}
|
||||
}
|
||||
|
||||
permuteNames() {
|
||||
local name=$1
|
||||
IFS="/" read -r user path <<< $name
|
||||
local options
|
||||
options=("${path}" "${user}-${path}")
|
||||
if [[ $? -ne 0 ]]; then return 1; fi
|
||||
echo ${options}
|
||||
}
|
||||
|
||||
askCloneName() {
|
||||
local repo=$1
|
||||
read -ra possibleNames <<< $(permuteNames ${repo})
|
||||
local allNames
|
||||
allNames=${possibleNames[@]}
|
||||
if [[ $? -ne 0 ]]; then return 1; fi
|
||||
local pick
|
||||
pick=$(echo ${allNames// /\\n} | fzf \
|
||||
--query "${possibleNames[1]}" \
|
||||
--print-query \
|
||||
--height "~50%" \
|
||||
--cycle \
|
||||
--border \
|
||||
--border-label " Name of Dir to Clone Into " \
|
||||
--color label:bold:cyan
|
||||
)
|
||||
# with --print-query we still get a negative exit code if the response was not an option
|
||||
if [[ -z $pick ]]; then return 1; fi
|
||||
|
||||
if echo $pick | grep -q "/"; then
|
||||
echoe "Your selection: $(echo $pick | grep --color=always "/") has a path delimiter (/) and is invalid";
|
||||
return 1;
|
||||
fi
|
||||
|
||||
echo ${pick}
|
||||
}
|
||||
|
||||
repo=$(showGuiAndPickRepo)
|
||||
if [[ $? -ne 0 ]]; then exit 1; fi
|
||||
USE_SSH=true
|
||||
if [[ $? -ne 0 ]]; then exit 1; fi
|
||||
url="ERROR_INVALID_URL"
|
||||
if [[ $? -ne 0 ]]; then exit 1; fi
|
||||
|
||||
if $USE_SSH; then
|
||||
url="git@github.com:${repo}.git"
|
||||
else
|
||||
url="https://github.com/${repo}.git"
|
||||
fi
|
||||
|
||||
cloneName=$(askCloneName ${repo})
|
||||
if [[ $? -ne 0 ]]; then exit 1; fi
|
||||
|
||||
gh repo clone ${url} ${cloneName}
|
||||
|
||||
echo ${cloneName}
|
|
@ -45,12 +45,16 @@ in
|
|||
(mkScript {
|
||||
name = "http2ssh";
|
||||
file = ./http2ssh.sh;
|
||||
env = [ pkgs.git ];
|
||||
env = with pkgs; [
|
||||
git
|
||||
];
|
||||
})
|
||||
(mkScript {
|
||||
name = "git_fetchAll";
|
||||
file = ./git_fetchAll.sh;
|
||||
env = [ pkgs.git ];
|
||||
env = with pkgs; [
|
||||
git
|
||||
];
|
||||
})
|
||||
(mkScript {
|
||||
name = "install_eslint";
|
||||
|
@ -59,7 +63,9 @@ in
|
|||
(mkScript {
|
||||
name = "math";
|
||||
file = ./math.sh;
|
||||
env = [ pkgs.python3 ];
|
||||
env = with pkgs; [
|
||||
python3
|
||||
];
|
||||
})
|
||||
(mkScript {
|
||||
name = "hashi18n";
|
||||
|
@ -68,8 +74,11 @@ in
|
|||
(mkScript {
|
||||
name = "flakeify";
|
||||
file = ./flakeify.sh;
|
||||
env = [ pkgs.direnv ];
|
||||
env = with pkgs; [
|
||||
direnv
|
||||
];
|
||||
})
|
||||
# impl for the cloneRepo command
|
||||
];
|
||||
file = {
|
||||
scripts = {
|
||||
|
@ -87,4 +96,30 @@ in
|
|||
p = "${builtins.readFile ./projectPicker.sh}";
|
||||
};
|
||||
};
|
||||
programs = {
|
||||
zsh = {
|
||||
initExtra =
|
||||
let
|
||||
implName = "cloneRepoImpl";
|
||||
in
|
||||
''
|
||||
cloneRepo() {
|
||||
local dir;
|
||||
dir=$(${
|
||||
(mkScript {
|
||||
name = implName;
|
||||
file = ./cloneRepoImpl.sh;
|
||||
env = with pkgs; [
|
||||
gh
|
||||
fzf
|
||||
];
|
||||
})
|
||||
}/bin/${implName})
|
||||
if [[ $? -eq 0 ]]; then
|
||||
cd ''${dir}
|
||||
fi
|
||||
}
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue