Skip to content

Commit

Permalink
Merge commit '04c4b5c4eb63226c274d836308c9fad53cca31cf' as 'command-h…
Browse files Browse the repository at this point in the history
…elper'
  • Loading branch information
neverkas committed Mar 23, 2023
2 parents f672e00 + 04c4b5c commit 9d44ac0
Show file tree
Hide file tree
Showing 46 changed files with 1,940 additions and 0 deletions.
3 changes: 3 additions & 0 deletions command-helper/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
applications.txt
linux-shell.txt
notes.txt
746 changes: 746 additions & 0 deletions command-helper/DOCUMENTATION.org

Large diffs are not rendered by default.

180 changes: 180 additions & 0 deletions command-helper/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
-include utils/utils.mk
-include utils/unix-utils.mk
-include config.cfg
-include utils/menus.mk

#SHELL=/bin/bash

DOC_NOTES_FILES = $(wildcard $(DOC_NOTES_DIRECTORY)/*.$(DOC_NOTES_EXTENSION))

DOC_COMANDOS_LINUX = $(wildcard $(DOC_COMMANDS_LINUX_DIRECTORY)/*.$(DOC_COMMANDS_EXTENSION))
DOC_SHORTCUTS_LINUX = $(wildcard $(DOC_SHORTCUTS_LINUX_DIRECTORY)/*.$(DOC_SHORTCUTS_EXTENSION))

DOC_COMANDOS_APPS = $(wildcard $(DOC_COMMANDS_APPS_DIRECTORY)/*.$(DOC_COMMANDS_EXTENSION))
DOC_SHORTCUTS_APPS = $(wildcard $(DOC_SHORTCUTS_APPS_DIRECTORY)/*.$(DOC_SHORTCUTS_EXTENSION))

COMANDOS_LINUX = $(basename $(notdir $(DOC_COMANDOS_LINUX)))
SHORTCUTS_LINUX = $(basename $(notdir $(DOC_SHORTCUTS_LINUX)))

COMANDOS_APPS = $(basename $(notdir $(DOC_COMANDOS_APPS)))
SHORTCUTS_APPS = $(basename $(notdir $(DOC_SHORTCUTS_APPS)))

COMANDOS = $(COMANDOS_LINUX) $(COMANDOS_APPS)

.DEFAULT_GOAL=help

# TODO: refactor, definir una función de Makefile que reciba por parámetro el nombre de target y las dependencias
$(DOC_LINUX).txt: $(DOC_COMANDOS_LINUX)
@$(TRUNCATE_CLEAR_CONTENT) $@
@$(foreach comando, $^,\
cat $(comando) | \
sed -n '$(CONTENT_NUMBER_LINE_CATEGORY),$(CONTENT_NUMBER_LINE_DESCRIPTION)p' | \
nawk 'BEGIN{print "$(basename $(notdir $(comando)))|" } {print $$0}' | \
sed -E 's/^\#\# ($(CONTENT_TAG_CATEGORY))\: (([[:alnum:]]|[[:space:]]|[[:punct:]])+)$$/\2\|/g' | \
sed -E 's/^\#\# ($(CONTENT_TAG_DESCRIPTION))\: (([[:alnum:]]|[[:space:]]|[[:punct:]])+)$$/\2;/g' | \
tr --delete '\n' | tr ';' '\n' \
>> $@;\
)

# TODO: refactor, definir una función de Makefile que reciba por parámetro el nombre de target y las dependencias
$(DOC_APPS).txt: $(DOC_COMANDOS_APPS)
@$(TRUNCATE_CLEAR_CONTENT) $@
@$(foreach comando, $^,\
cat $(comando) | \
sed -n '$(CONTENT_NUMBER_LINE_CATEGORY),$(CONTENT_NUMBER_LINE_DESCRIPTION)p' | \
nawk 'BEGIN{print "$(basename $(notdir $(comando)))|" } {print $$0}' | \
sed -E 's/^\#\# ($(CONTENT_TAG_CATEGORY))\: (([[:alnum:]]|[[:space:]]|[[:punct:]])+)$$/\2\|/g' | \
sed -E 's/^\#\# ($(CONTENT_TAG_DESCRIPTION))\: (([[:alnum:]]|[[:space:]]|[[:punct:]])+)$$/\2;/g' | \
tr --delete '\n' | tr ';' '\n' \
>> $@;\
)

$(DOC_NOTES).txt: $(DOC_NOTES_FILES)
@$(TRUNCATE_CLEAR_CONTENT) $@
@$(foreach nota, $^,\
cat $(nota) | \
sed -n '$(CONTENT_NUMBER_LINE_CATEGORY),$(CONTENT_NUMBER_LINE_DESCRIPTION)p' | \
nawk 'BEGIN{print "$(basename $(notdir $(nota)))|" } {print $$0}' | \
sed -E 's/^\#\+($(CONTENT_TAG_CATEGORY))\: (([[:alnum:]]|[[:space:]]|[[:punct:]])+)$$/\2\|/g' | \
sed -E 's/^\#\+($(CONTENT_TAG_DESCRIPTION))\: (([[:alnum:]]|[[:space:]]|[[:punct:]])+)$$/\2;/g' | \
tr --delete '\n' | tr ';' '\n' \
>> $@;\
)

##@ Listar documentación
l linux-commands: $(DOC_LINUX).txt ## Listado Comandos de terminal Linux
@echo 'Lista de Comandos'
@cat $< | $(SORT_BY_COLUMN) 2 | $(NAWK_ORDER_FIELDS) | $(NAWK_HEADERS)

a applications-commands: $(DOC_APPS).txt ## Listado Comandos de Aplicaciones
@echo 'Lista de Comandos para Aplicaciones'
@cat $< | $(SORT_BY_COLUMN) 2 | $(NAWK_ORDER_FIELDS) | $(NAWK_HEADERS)

n notes: $(DOC_NOTES).txt ## Notas sugeridas
@$(MENU_SHOW_NOTES) 3>&1 1>&2 2>&3 \
| xargs -I % $(EDITOR_NOTE) $(DOC_NOTES_DIRECTORY)/%.$(DOC_NOTES_EXTENSION)

##@ Creación y Edición de documentación

# Notas:
# 1. La opción elegida en el menú será capturada por xargs
# 2. La opción capturada será el target que pasaremos por parámetro al propio Makefile para ejecutar
# 3. Con $(MAKE) se invoca a si mismo el Makefile
# 4. El motivo del redireccionamiento se explica en el target linux-create-doc
# TODO: refactor, lógica repetida
create-doc: ## Crear documentación de Linux ó de una Aplicación
@$(MENU_CREATE_DOC) 3>&1 1>&2 2>&3 \
| xargs -I % $(MAKE) --no-print-directory %

edit-doc: ## Editar documentación de Linux ó de una Aplicación
@$(MENU_EDIT_DOC) 3>&1 1>&2 2>&3 \
| xargs -I % $(MAKE) --no-print-directory %

# TODO: refactor, lógica repetida
linux-edit-commands: $(DOC_LINUX).txt
@$(MENU_EDIT_LINUX_COMMANDS) 3>&1 1>&2 2>&3 \
| xargs -I % $(TEXT_EDITOR) $(DOC_COMMANDS_LINUX_DIRECTORY)/%.$(DOC_COMMANDS_EXTENSION)

linux-edit-shortcuts:
@$(MENU_EDIT_LINUX_SHORTCUTS) 3>&1 1>&2 2>&3 \
| xargs -I % $(TEXT_EDITOR) $(DOC_SHORTCUTS_LINUX_DIRECTORY)/%.$(DOC_SHORTCUTS_EXTENSION)

app-edit-commands:
@$(MENU_EDIT_APPS_COMMANDS) 3>&1 1>&2 2>&3 \
| xargs -I % $(TEXT_EDITOR) $(DOC_COMMANDS_APPS_DIRECTORY)/%.$(DOC_COMMANDS_EXTENSION)

app-edit-shortcuts:
@$(MENU_EDIT_APPS_COMMANDS) 3>&1 1>&2 2>&3 \
| xargs -I % $(TEXT_EDITOR) $(DOC_SHORTCUTS_APPS_DIRECTORY)/%.$(DOC_SHORTCUTS_EXTENSION)

# Notas:
# 1. el comando xargs requiere utilizarlo la forma xargs -I % sh -c 'comando1 %; comando2 %; ..'
# para pasar el mismo parámetro % a multiples comandos en la misma shell
#
# 2. el símbolo % que usamos en los nombres de los ficheros, es el parámetro capturado por el comando xargs con la opción -I
#
# 3. el comando whiptail escribe sobre stdout (fd 2) por tanto creamos un nuevo File Descriptor (3),
# que apunta al stdout (fd 1), para luego redireccionar el stdout->stderr, y redireccionar el stderr->nuevo fd 3 (que apunta al stdout)
linux-create-doc:
@whiptail --inputbox "Escriba el nombre del comando" 25 80 --title "Crear Documentación de Linux" 3>&1 1>&2 2>&3 \
| xargs -I % sh -c \
"$(COPY_NOT_OVERWRITE) $(DOC_COMMANDS_LINUX_DIRECTORY)/.template $(DOC_COMMANDS_LINUX_DIRECTORY)/%.$(DOC_COMMANDS_EXTENSION); \
$(COPY_NOT_OVERWRITE) $(DOC_SHORTCUTS_LINUX_DIRECTORY)/.template $(DOC_SHORTCUTS_LINUX_DIRECTORY)/%.$(DOC_SHORTCUTS_EXTENSION); \
echo 'Se creó el archivo $(DOC_COMMANDS_LINUX_DIRECTORY)/%.$(DOC_COMMANDS_EXTENSION);' \
echo 'Se creó el archivo $(DOC_SHORTCUTS_LINUX_DIRECTORY)/%.$(DOC_SHORTCUTS_EXTENSION);'"

# TODO: lógica repetida con linux-create-doc
app-create-doc:
@whiptail --inputbox "Escriba el nombre del comando" 25 80 --title "Crear Documentación de Linux" 3>&1 1>&2 2>&3 \
| xargs -I % sh -c \
"$(COPY_NOT_OVERWRITE) $(DOC_COMMANDS_APPS_DIRECTORY)/.template $(DOC_COMMANDS_APPS_DIRECTORY)/%.$(DOC_COMMANDS_EXTENSION); \
$(COPY_NOT_OVERWRITE) $(DOC_SHORTCUTS_APPS_DIRECTORY)/.template $(DOC_SHORTCUTS_APPS_DIRECTORY)/%.$(DOC_SHORTCUTS_EXTENSION); \
echo 'Se creó el archivo $(DOC_COMMANDS_APPS_DIRECTORY)/%.$(DOC_COMMANDS_EXTENSION);' \
echo 'Se creó el archivo$(DOC_SHORTCUTS_APPS_DIRECTORY)/%.$(DOC_SHORTCUTS_EXTENSION);'"

# TODO: lógica repetida con COMANDOS_APPS
$(COMANDOS_LINUX):
@test -f $(DOC_SHORTCUTS_LINUX_DIRECTORY)/$@.$(DOC_SHORTCUTS_EXTENSION) \
&& $(BAT) $(DOC_COMMANDS_LINUX_DIRECTORY)/$@.$(DOC_COMMANDS_EXTENSION) $(DOC_SHORTCUTS_LINUX_DIRECTORY)/$@.$(DOC_SHORTCUTS_EXTENSION) \
|| $(BAT) $(DOC_COMMANDS_LINUX_DIRECTORY)/$@.$(DOC_COMMANDS_EXTENSION)

$(COMANDOS_APPS):
@test -f $(DOC_SHORTCUTS_APPS_DIRECTORY)/$@.$(DOC_SHORTCUTS_EXTENSION) \
&& $(BAT) $(DOC_COMMANDS_APPS_DIRECTORY)/$@.$(DOC_COMMANDS_EXTENSION) $(DOC_SHORTCUTS_APPS_DIRECTORY)/$@.$(DOC_SHORTCUTS_EXTENSION) \
|| $(BAT) $(DOC_COMMANDS_APPS_DIRECTORY)/$@.$(DOC_COMMANDS_EXTENSION)

##@ Utilidades
h help: ## Mostrar menú de ayuda
@awk 'BEGIN {FS = ":.*##"; printf "\nOpciones para usar:\n make \033[36m\033[0m\n"} /^[$$()% 0-9a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

install-utils:
ifeq ("$(shell which bat)","")
@sudo aptitude install -y bat
endif

ri re-install: remove install

check-installed:
ifeq ($(APP_INSTALLED), true)
$(error La aplicación ya está instalada)
endif

i install: check-installed install-utils ## Instalar aplicación
@$(BOX_CONFIRM_INSTALL) \
&& test $(EXIT_STATUS) -eq $(EXIT_STATUS_SUCCESS) \
&& (echo $(BASH_ALIAS) >> $(BASH_ALIASES_FILE) \
&& chmod u+x $(UTILS_DIRECTORY)/update-bash-aliases \
&& $(UTILS_DIRECTORY)/update-bash-aliases) \
|| true

r remove: ## Desinstalar aplicación
@$(BOX_CONFIRM_UNINSTALL) \
&& test $(EXIT_STATUS) -eq $(EXIT_STATUS_SUCCESS) \
&& sed -i "/^alias $(BASH_ALIAS_SYMBOL)='make.*APP_AUTHOR=$(APP_AUTHOR)/d" $(BASH_ALIASES_FILE) \
&& $(UTILS_DIRECTORY)/update-bash-aliases \
|| true

# %:
# $(error NO existe el comando)

.PHONY: i install ri re-install install-utils r remove h help l linux-commands a applications-commands n notes
71 changes: 71 additions & 0 deletions command-helper/README.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#+TITLE: Command Helper
* Intro
** ¿Qué es?
- programa sencillo sin tantas dependencias, similar al comando ~man~ para documentar comandos
- describe los comandos más utiles en un archivo ~.sh~
- describe los atajos más comunes en un archivo ~.org~
- accede desde una terminal de forma global con el símbolo ~?~
** ¿Por qué lo utilizo?
- no utilizar ciertos comandos por un tiempo, implíca olvidarse de como usarlos y sus parámetros
- evitar perder tiempo leyendo ~man comando~ que tiene tantas opciones avanzadas en vez una explicación simple
* Ejemplo
#+BEGIN_SRC shell
# imprimirá un menú de ayuda, opciones de instalación, etc..
? help

# leerá las entradas documentadas del comando ls
# con los usos más comunes que hayas escrito
? ls

# leerá las entradas del archivo doc/linux-shell/commands/screen.sh y también doc/linux-shell/shortcuts/screen.org (si los tuviera)
? screen
#+END_SRC
* Instalación y Desinstalación
#+BEGIN_SRC shell
# se agregará un alias de bash del directorio actual en ~/.bash_aliases
# que te permitirá ejecutar el programa en la terminal usando sólo el símbolo de interrogación
make install

# para desinstalar
# eliminará el código de ~/.bash_aliases y también el alias vinculada a la shell
make remove
#+END_SRC
* Configuración
** Documentando comandos y shortcuts
#+BEGIN_QUOTE
La configuración para documentar un nuevo comando de la terminal de linux es mínima
1. Creamos el archivo con el nombre del comando a documentar en el directorio ~doc/linux-shell/commands/~ con la extensión ~.sh~
2. También podemos crear una tabla de los shortcuts del comando en ~doc/linux-shell/shortcuts/~ con la extensión ~.org~
3. Listo! podemos reutilizar los archivos creados como template

Documentar comandos de aplicaciones es lo mismo, pero usamos el directorio ~doc/applications/commands~ y ~doc/applications/shortcuts/~
#+END_QUOTE
** Metadata al documentar
Al comienzo de cada archivo ~.sh~ debe tener las siguientes dos lineas (es importante respetar el formato)
- ~## CATEGORIA: texto~ clasifica el comando en un grupo particular
- ~## DESCRIPCION: texto~ describe el comando en si, que es lo que hace

#+BEGIN_QUOTE
El siguiente sería un ejemplo del archivo ~doc/commands/ls.sh~ para entender la metadata
#+END_QUOTE

#+BEGIN_SRC shell
## CATEGORIA: operaciones con archivo
## DESCRIPCION: listar archivos y directorios

# listar archivos ocultos
ls -la

# listar archivos ordenados por tamaño del archivo
ls -ls
#+END_SRC
* Referencias
** Referencias Extraoficiales
#+BEGIN_COMMENT
pendiente validar
1) https://www.fpgenred.es/GNU-Linux/
2) https://www.tecmint.com/category/linux-commands/
3) https://linuxopsys.com/
4) https://geekland.eu/category/linux-2/
5) https://phoenixnap.com/kb/tag/linux
#+END_COMMENT
41 changes: 41 additions & 0 deletions command-helper/config.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# utilizado en los popup_edit
TEXT_EDITOR=nvim

# utilizado en un cat archivo | sed -n '1p'
# (sólo imprimirá ese número de linea)
CONTENT_NUMBER_LINE_CATEGORY=1
CONTENT_NUMBER_LINE_DESCRIPTION=2

# utilizados en un cat archivo | sed -E 's/^(content_tag_here): (.*)$/ \2/g'
# (obtener el texto de las lineas que contengan esos tags al principio)
CONTENT_TAG_CATEGORY=CATEGORIA
CONTENT_TAG_DESCRIPTION=DESCRIPCION

# utilizado en un bat --line-range 4: archivo
# (imprimirá a partir de ese numero de linea hasta el final del archivo)
NUMBER_LINE_BEGIN_DOCUMENTATION=4
NUMBER_LINE_BEGIN_DOC_NOTES=3

UTILS_DIRECTORY=utils

DOC_DIRECTORY=doc

DOC_COMMANDS_DIRECTORY=commands
DOC_COMMANDS_EXTENSION=sh

DOC_SHORTCUTS_DIRECTORY=shortcuts
DOC_SHORTCUTS_EXTENSION=org

DOC_NOTES_EXTENSION=org

DOC_APPS=applications
DOC_LINUX=linux-shell
DOC_NOTES=notes

DOC_COMMANDS_LINUX_DIRECTORY=$(DOC_DIRECTORY)/$(DOC_LINUX)/$(DOC_COMMANDS_DIRECTORY)
DOC_SHORTCUTS_LINUX_DIRECTORY=$(DOC_DIRECTORY)/$(DOC_LINUX)/$(DOC_SHORTCUTS_DIRECTORY)

DOC_COMMANDS_APPS_DIRECTORY=$(DOC_DIRECTORY)/$(DOC_APPS)/$(DOC_COMMANDS_DIRECTORY)
DOC_SHORTCUTS_APPS_DIRECTORY=$(DOC_DIRECTORY)/$(DOC_APPS)/$(DOC_SHORTCUTS_DIRECTORY)

DOC_NOTES_DIRECTORY=$(DOC_DIRECTORY)/notes
8 changes: 8 additions & 0 deletions command-helper/doc/applications/commands/.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## CATEGORIA: clasificar aplicación
## DESCRIPCION: describir aplicación

# un comentario, imprimimos un hola
echo "hola"

# otro comentario, imprimimos un chau
echo "chau"
6 changes: 6 additions & 0 deletions command-helper/doc/applications/commands/docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## CATEGORIA: contenedores y maquinas virtuales
## DESCRIPCION: empaqueta aplicaciones en contenedores similares a maquinas virtuales

# eliminar todas las imagenes en desuso que son más antiguas a un número de horas
# (https://docs.docker.com/engine/reference/commandline/image_prune/)
docker image prune -a --force --filter "until=1h"
2 changes: 2 additions & 0 deletions command-helper/doc/applications/commands/logseq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## CATEGORIA: gestión de notas y tareas
## DESCRIPCION: gestor de conocimiento personal, grafos de conocimientos (vincula ideas)
14 changes: 14 additions & 0 deletions command-helper/doc/applications/commands/neovim.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## CATEGORIA: editor de texto
## DESCRIPCION: editor de texto basado en Vim

# Desactivar las palabras resaltadas hasta la próxima búsqueda
:noh

# Mostrar número de linea
:setnumber

# Buscar/Reemplazar en la misma linea que el cursor
.s/cadena/nueva/g

# Buscar/Reemplazar globalmente pero pide confirmación al reemplazar
s/cadena/nueva/gc
8 changes: 8 additions & 0 deletions command-helper/doc/applications/commands/qutebrowser.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## CATEGORIA: navegador web
## DESCRIPCION: navegador web minimalista basado en Vim

# Cerrar navegador
:q

# Guardar las pestañas y cerrar Navegador
:wq
11 changes: 11 additions & 0 deletions command-helper/doc/applications/shortcuts/.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#+NAME: atajos
| Atajo | Descripción |
|------------+-----------------|
| Alt + F4 | Cerrar programa |
| Ctrl Alt F | Abrir terminal |

#+NAME: otros-atajos
| Atajo | Descripción |
|------------+-----------------|
| Alt + F4 | Cerrar programa |
| Ctrl Alt F | Abrir terminal |
8 changes: 8 additions & 0 deletions command-helper/doc/applications/shortcuts/logseq.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
| Atajo | Descripción |
|-----------------------------+----------------------------------------------------|
| t r | Toggle right sidebar |
| t l | Toggle left sidebar |
| t o | Toggle open blocks (collapse or expand all blocks) |
| Ctrl w | close logseq |
| Shift Alt UpArrow/DownArrow | Deslizar tareas |
| Ctrl K | Search or Create a Page |
26 changes: 26 additions & 0 deletions command-helper/doc/applications/shortcuts/neovim.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
| Atajo | Descripción |
|-------------------+-------------------------------------------------------|
| k,j,h,l | Mover cursor up, down, left, right |
| r+nuevoCaracter | Sustituir el caracter donde esté el cursor |
| f+caracterABuscar | Buscar caracter desde el cursor hasta fin de linea |
| F+caracterABuscar | Buscar caracter desde el cursor al principio de linea |

| Atajo | Descripción |
|-------+------------------------------------------|
| gg | Cursor al principio del archivo |
| G | Cursor al fin del archivo |
| w | Avanzar a la siguiente palabra |
| b | Retroceder a la anterior palabra |
| 0 | Cursor al principio de linea |
| $ | Cursor al fin de linea |
| i | Editar en donde esté el cursor |
| a | Editar un caracter adelante al cursor |
| I | Editar en el primer caracter de la linea |
| A | Editar al fin de linea |

| Atajo | Descripción |
|-------+-----------------------------------------------------------------------------|
| v+$ | Seleccionar texto hasta fin de linea |
| v+^ | Seleccionar texto hasta el principio de linea |
| v+% | Seleccionar texto hasta donde balancee alguno de los operadores (,{, [ |
| 5i* | Repetir 5 veces el escribir el símbolo asterisco (util para separar textos) |
Loading

0 comments on commit 9d44ac0

Please sign in to comment.