• Operand
  • # (b)ring mi - belles.

gram:build

> ./config/nushell/hub.nu

Lenses
(coming soon!)


def "hub place" [--org (-o): string, --base: string] {
  let base = if ($base == 'harbor') {
    bind media ~/media; echo ~/media | path expand
  } else {
    let p = "~/disc/nvme0n1p5/rebase.hub" | path expand;
    if not ($p | path exists) { disc bind nvme0n1p5 }; $p }

  if ($org | is-empty) { $base } else {
    [ $base ($org | path basename) ] | path join | path expand
  }
}

def "hub clone" [base: string] {
  let address = $"git@github.com:($base)"; let name = $"(basename $address)";
  if (($name) | path exists) { cd $name; code fetch; code pull;
  } else { git clone $"($address)" } | print; }

# code handles; mnemonic helpers.
def "hub base" [ --org (-o): string, --page: number = 1 ] {
  print $org
  let bases = http get $"https://api.github.com/users/($org)/repos?per_page=100&page=($page)"
  if ($bases | is-empty) { [] } else {
    $bases ++ (hub base -o $org --page ($page + 1))
  } }

def "hub rebase" [
  --all (-a),
  --org (-o),
  ...names: string,
] {
  if ($all) {
    let place = hub place; mkdir $place
# let log = [ $place $"_.(clock | str trim).clone.log" ] | path join | path expand
    let orgs = (ls (hub place) | where type == 'dir').name | path basename
    $orgs | tee { print } | each {|org| hub rebase -o $org }
# cd (hub place -o $org);
# (hub base -o $org).full_name | par-each { |b| hub clone $b } | tee { print } | save -a $log
  } else if ($org) {
    $names | each {|org|
      print $org
      let place = hub place -o $org; mkdir $place; cd $place
      let log = $"($place).(clock | str trim).clone.log" | path expand
      (hub base -o $org) | par-each { |b| hub clone $b.full_name  } | tee { print } | save -a $log
    }
  } else {
    echo "Please choose (o)rg-copy mode or upgrade-(a)ll mode. See `hub rebase -h`"
  }
}

# def "hub issue" [
#   --org (-o): string,
#   --base (-b): string,
#   --number (-n): int,
# ] { http get $"https://api.github.com/repos/($org)/($base)/issues/($number)" }

def "hub issue" [
  org: string,
  base: string,
  number: int,
] { http get $"https://api.github.com/repos/($org)/($base)/issues/($number)" }