repositories

NixDaemon

NixOS pentest workstation as one flake — IceBreaker's successor

clonegit clone https://git.daemon-sec.xyz/NixDaemon.git
_rcx90 lines3.1 KiBraw download
#compdef rcx
# rcx — modes, wrapper flags, then remotes (from rclone's own config) and paths.
local -a modes wrapper_flags remotes
modes=(
  'copy:copy/update to the far side; nothing is deleted'
  'preview:dry run, with a hardlink cost report'
  'mirror:make the destination match the source (deletes there)'
  'move:copy, then delete each source file that arrived'
  'job:run a copy detached as a systemd user unit'
  'service:create, list, show or remove an installed service'
  'jobs:list detached rcx jobs'
  'watch:follow a job log'
  'stop:end a job early'
  'check:verify a finished transfer'
  'ls:list a remote path'
  'size:count and bytes'
  'about:remote quota'
  'remotes:what is configured'
  'mount:start or list the rclone mount units'
  'unmount:stop a mount unit'
  'raw:exact rclone invocation'
  'cheat:reference card'
  'help:wrapper help'
)
wrapper_flags=(
  '--yes[confirm a mode that deletes things]'
  '--schedule[when an installed service runs]:OnCalendar:(daily hourly weekly monthly)'
  '--boot[also start the service at login]'
  '--now[enable and start it immediately]'
  '--force[replace an existing rcx unit]'
  '--command[print the command without running it]'
  '--plain[no decoration]'
  '--no-guard[allow a path inside a cloud mount]'
  '--name[name a detached job]:job name:'
)

_rcx_remotes() {
  local -a found
  found=(${(f)"$(rclone listremotes 2>/dev/null)"})
  (( ${#found} )) && _describe -t remotes 'rclone remote' found
}
_rcx_jobs() {
  local -a units
  units=(${${${(f)"$(systemctl --user list-units --all --no-legend --plain --type=service 'rcx-*' 2>/dev/null)"}%%.service*}##rcx-})
  (( ${#units} )) && _describe -t jobs 'rcx job' units
}
_rcx_mounts() {
  local -a units
  units=(${${${(f)"$(systemctl --user list-unit-files --no-legend --plain 'rclone-*.service' 2>/dev/null)"}%%.service*}##rclone-})
  (( ${#units} )) && _describe -t mounts 'mount unit' units
}

local idx=2 mode=''
while (( idx < CURRENT )) && [[ ${words[idx]} == --* ]]; do
  [[ ${words[idx]} == '--name' ]] && (( idx++ ))
  (( idx++ ))
done
if (( idx < CURRENT )) && [[ -n ${modes[(r)${words[idx]}:*]} ]]; then
  mode=${words[idx]}
fi

_rcx_services() {
  local -a names
  names=(${${(f)"$(print -l ~/.config/systemd/user/rcx-*.service(N:t:r))"}##rcx-})
  (( ${#names} )) && _describe -t services 'rcx service' names
}

case $mode in
  service)
    if (( CURRENT == idx + 1 )); then
      _values 'action' create list show rm
    elif [[ ${words[idx+1]} == (show|rm) ]]; then
      _rcx_services
    else
      _arguments -S $wrapper_flags '*:path or remote:->target'
      [[ $state == target ]] && { _rcx_remotes; _files }
    fi
    return ;;
  watch|stop)   _rcx_jobs; _rcx_services; return ;;
  mount|unmount) [[ ${words[idx+1]} == create ]] && { _rcx_remotes; _files; return }
                 _rcx_mounts; _values 'action' create; return ;;
  cheat)        _values 'section' all transfer job service verify limits mount; return ;;
  jobs|remotes|help) return ;;
  '')           _describe -t commands 'rcx mode' modes ;;
esac
_arguments -S $wrapper_flags '*:path or remote:->target'
if [[ $state == target ]]; then
  _rcx_remotes
  _files
fi