Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ jobs:
run: |
fish fish/tests/w2-core.fish
fish fish/tests/w3-helpers.fish
fish fish/tests/w4b-screenshots.fish
fish fish/tests/w5a-hremote.fish
fish fish/tests/w5b-herdr-ssh.fish
fish fish/tests/w6-agent-helpers.fish

- name: Validate JSON configs
shell: bash
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,31 @@ Para validar sin tocar identidades reales ni la red:
/opt/homebrew/bin/fish fish/tests/w3-helpers.fish
```

## Helpers Fish: screenshots (W4b)

W4b agrega `ss`, `last`, `ssd` e `imgclip` sin capturar la pantalla ni leer el clipboard durante la carga. `SCREENSHOTS_DIR` usa el override solo si apunta a un directorio existente; si no, conserva el fallback de macOS: `~/Screenshots` cuando existe y luego `~/Desktop`. Home Manager mapea cada función explícitamente y no administra el directorio, screenshots ni clipboard del host.

Para validar con `HOME`, `PATH` y comandos macOS falsos aislados:

```bash
/opt/homebrew/bin/fish fish/tests/w4b-screenshots.fish
```

## Helpers Fish de agentes (W6)

**ADVERTENCIA:** por elección explícita del owner, `cc` ejecuta Claude Code con `--dangerously-skip-permissions` y `oc`/`ocb` ejecutan OpenCode con `--auto`; estos shortcuts intencionalmente omiten o autoaprueban permisos. W6 agrega `cc`, `oc`, `ocb`, `ccx`, `ccd` y `ccclip` como helpers Fish opt-in en el directorio validado; `ccx` entrega el contexto por stdin y `ccclip` escribe al clipboard solo al invocarse. No incluye `ccb`.

| Área | Owner en W6 |
| --- | --- |
| Helpers y soporte privado | `fish/functions/{_cortex_resolve_target,_cortex_run_agent,cc,oc,ocb,ccx,ccd,ccclip}.fish` |
| Home Manager | Mapea cada una de esas funciones de forma explícita; no administra binarios de agentes, clipboard, worktrees, estado, historial ni configuración de proveedores |

Para validar con agentes y clipboard falsos aislados:

```bash
/opt/homebrew/bin/fish fish/tests/w6-agent-helpers.fish
```

## Estructura

```
Expand Down
11 changes: 11 additions & 0 deletions fish/functions/_cortex_resolve_target.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function _cortex_resolve_target
set -l target "$argv[1]"
test -n "$target"; or set target .

if not test -d "$target"
printf 'Directorio no encontrado: %s\n' "$target" >&2
return 1
end

cd "$target"; and pwd
end
11 changes: 11 additions & 0 deletions fish/functions/_cortex_run_agent.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function _cortex_run_agent
set -l target "$argv[1]"
set -e argv[1]
set -l original_dir "$PWD"

cd "$target"; or return 1
command $argv
set -l agent_status $status
cd "$original_dir"; or return 1
return "$agent_status"
end
20 changes: 20 additions & 0 deletions fish/functions/_screenshot_files.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function _screenshot_files
set -l directory (_screenshots_dir)
set -l files

# BSD find lacks GNU -maxdepth, so retain the source helper's two-level scope in Fish.
for file in (command find "$directory" -type f -print0 2>/dev/null | string split0)
set -l relative (string replace -- "$directory/" '' "$file")
set -l components (string split / -- "$relative")
test (count $components) -le 2; or continue

switch (path extension "$file")
case .png .jpg .jpeg .gif
set -a files "$file"
end
end

if test (count $files) -gt 0
command ls -t $files 2>/dev/null
end
end
13 changes: 13 additions & 0 deletions fish/functions/_screenshots_dir.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function _screenshots_dir
if set -q SCREENSHOTS_DIR; and test -n "$SCREENSHOTS_DIR"; and test -d "$SCREENSHOTS_DIR"
printf '%s\n' "$SCREENSHOTS_DIR"
return
end

set -l default "$HOME/Screenshots"
if test -d "$default"
printf '%s\n' "$default"
else
printf '%s\n' "$HOME/Desktop"
end
end
20 changes: 20 additions & 0 deletions fish/functions/_time_ago.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function _time_ago
set -l file "$argv[1]"
set -l now (command date +%s)
set -l mtime (command stat -f %m "$file" 2>/dev/null)

if test $status -ne 0; or test -z "$mtime"
set mtime "$now"
end

set -l difference (math "$now - $mtime")
if test "$difference" -lt 60
printf 'justo ahora\n'
else if test "$difference" -lt 3600
printf '%sm ago\n' (math "$difference / 60")
else if test "$difference" -lt 86400
printf '%sh ago\n' (math "$difference / 3600")
else
printf '%sd ago\n' (math "$difference / 86400")
end
end
5 changes: 5 additions & 0 deletions fish/functions/cc.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Usage: cc [path]
function cc
set -l resolved (_cortex_resolve_target "$argv[1]"); or return 1
_cortex_run_agent "$resolved" claude --dangerously-skip-permissions
end
43 changes: 43 additions & 0 deletions fish/functions/ccclip.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Usage: ccclip <file...> [-n|--line-numbers]
function ccclip
if test (count $argv) -eq 0
printf 'Uso: ccclip <archivo1> [archivo2 ...] [-n|--line-numbers]\n' >&2
return 1
end

set -l with_numbers false
set -l files
for arg in $argv
switch "$arg"
case -n --line-numbers
set with_numbers true
case '*'
set -a files "$arg"
end
end

begin
for file in $files
if not test -f "$file"
printf 'Archivo no encontrado: %s\n' "$file" >&2
continue
end

set -l extension (path extension "$file" | string trim -c .)
printf '```%s\n// File: %s\n' "$extension" "$file"
set -l content
if test "$with_numbers" = true
set content (nl -ba "$file" | string collect)
else
set content (command cat "$file" | string collect)
end
printf '%s\n```\n\n' "$content"
end
end | pbcopy
set -l clipboard_status $pipestatus[-1]
if test "$clipboard_status" -ne 0
return "$clipboard_status"
end

printf 'Contexto copiado al clipboard (%d archivos)\n' (count $files)
end
16 changes: 16 additions & 0 deletions fish/functions/ccd.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Usage: ccd [subpath]
function ccd
set -l subpath "$argv[1]"
set -l workspace "$WORKSPACE_DIR"
test -n "$workspace"; or set workspace "$HOME/dev"
set -l target "$workspace"
test -n "$subpath"; and set target "$workspace/$subpath"

if test -d "$target"
cd "$target"
printf 'Navegando a: %s\n' "$target"
else
printf 'Directorio no encontrado: %s\n' "$target" >&2
return 1
end
end
14 changes: 14 additions & 0 deletions fish/functions/ccx.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Usage: ccx <context> [path]
function ccx
set -l context "$argv[1]"
if test -z "$context"
printf 'Uso: ccx <contexto> [directorio]\n' >&2
return 1
end

set -l resolved (_cortex_resolve_target "$argv[2]"); or return 1
begin
printf '%s\n' "$context" | _cortex_run_agent "$resolved" claude
return $pipestatus[-1]
end
end
21 changes: 21 additions & 0 deletions fish/functions/imgclip.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Usage: imgclip <image> copies a supported image to the macOS clipboard.
function imgclip
set -l image "$argv[1]"

if not test -f "$image"
printf '❌ Archivo no encontrado: %s\n' "$image"
return 1
end

set -l extension (string lower -- (string replace -r '^.*\.' '' -- "$image"))
switch "$extension"
case png jpg jpeg gif bmp tiff
set -l resolved (path resolve "$image")
command osascript -e "set the clipboard to (read (POSIX file \"$resolved\") as «class PNGf»)" 2>/dev/null
or command osascript -e "set the clipboard to POSIX file \"$resolved\""
printf '✓ Imagen copiada al clipboard: %s\n' (command basename "$image")
case '*'
printf '❌ Formato no soportado: %s\n' "$extension"
return 1
end
end
33 changes: 33 additions & 0 deletions fish/functions/last.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Usage: last [-c|--copy] [-o|--open] prints, copies, or opens the latest screenshot.
function last
set -l copy false
set -l open_file false

for argument in $argv
switch "$argument"
case -c --copy
set copy true
case -o --open
set open_file true
end
end

set -l directory (_screenshots_dir)
set -l files (_screenshot_files)
set -l file "$files[1]"

if test -z "$file"
printf '⚠️ No se encontraron screenshots en: %s\n' "$directory"
return 1
end

if test "$copy" = true
printf '%s\n' "$file" | command pbcopy
printf '✓ Path copiado: %s\n' (command basename "$file")
else if test "$open_file" = true
command open "$file"
printf '✓ Abriendo: %s\n' (command basename "$file")
else
printf '%s\n' "$file"
end
end
9 changes: 9 additions & 0 deletions fish/functions/oc.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Usage: oc [path]
function oc
set -l resolved (_cortex_resolve_target "$argv[1]"); or return 1
set -l flags
if set -q OPENCODE_DEFAULT_FLAGS; and test -n "$OPENCODE_DEFAULT_FLAGS"
set flags (string replace -ra '[[:space:]]+' \n -- "$OPENCODE_DEFAULT_FLAGS")
end
_cortex_run_agent "$resolved" opencode --auto $flags
end
4 changes: 4 additions & 0 deletions fish/functions/ocb.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Usage: ocb [path]
function ocb
oc $argv
end
27 changes: 27 additions & 0 deletions fish/functions/ss.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Usage: ss [count] lists the most recent screenshots.
function ss
set -l count "$argv[1]"
test -n "$count"; or set count 10
set -l directory (_screenshots_dir)

if not test -d "$directory"
printf '⚠️ Directorio no encontrado: %s\n' "$directory"
printf ' Configurá SCREENSHOTS_DIR en local/env.zsh\n'
return 1
end

printf '\n📸 Últimos %s screenshots en: %s\n\n' "$count" "$directory"

set -l index 1
for file in (_screenshot_files)
set -l name (command basename "$file")
set -l size (command du -sh "$file" 2>/dev/null | command cut -f1)
set -l ago (_time_ago "$file")
printf ' [%d] \033[1;37m%s\033[0m \033[90m(%s) — %s\033[0m\n' "$index" "$name" "$size" "$ago"

set index (math "$index + 1")
test "$index" -le "$count"; or break
end

printf '\n Usá \033[1;33mlast\033[0m para obtener el path del último screenshot\n\n'
end
10 changes: 10 additions & 0 deletions fish/functions/ssd.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Usage: ssd opens the configured screenshots directory in Finder.
function ssd
set -l directory (_screenshots_dir)

if test -d "$directory"
command open "$directory"
else
printf '⚠️ Directorio no encontrado: %s\n' "$directory"
end
end
Loading
Loading