11 de marzo de 2020 [bash, Programming, Tech]
Me gusta la finalización de pestañas de Bash y la quiero para los comandos que escribo, para que pueda completar automáticamente partes de la línea de comandos cuando ejecuto mis programas.
Código
Aquí está el script (install-bash-completion) que escribí para configurarlo (no se requiere root, se instala en ~/.local):
#!/bin/bash
set -u
set -e
DIR=${BASH_COMPLETION_USER_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion}/completions
mkdir -p ${DIR}
cp _myprogram ${DIR}
El script de finalización real (_myprogram) que instala tiene este aspecto:
_myprogram_commands()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts=$(bash -c "./myprogram --commands")
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
}
complete -F _myprogram_commands ./myprogram
Instalar
Para instalarlo ejecute:
./install-bash-completion
Luego cierre sesión y vuelva a iniciar sesión.
Ahora, cuando escriba ./myprogram y presione TAB varias veces, verá una lista de posibles finalizaciones.
Notas
El script de finalización debe llevar el nombre del programa, con un guión bajo delante.
Si quiero que esto funcione cuando esté instalado en mi RUTA, necesito cambiar ./myprogram a solo myprogram en 2 lugares.
Tenga en cuenta la línea opts=$(bash -c “./myprogram –commands”): esto realmente ejecuta mi programa para obtener la lista de finalización. Esto significa que mi programa debe aceptar la opción –commands que imprime comandos válidos. O puedo codificarlo reemplazando esa línea con solo:
opts="cmd1 cmd2 --help --etc"
Más información:
PakarPBN
A Private Blog Network (PBN) is a collection of websites that are controlled by a single individual or organization and used primarily to build backlinks to a “money site” in order to influence its ranking in search engines such as Google. The core idea behind a PBN is based on the importance of backlinks in Google’s ranking algorithm. Since Google views backlinks as signals of authority and trust, some website owners attempt to artificially create these signals through a controlled network of sites.
In a typical PBN setup, the owner acquires expired or aged domains that already have existing authority, backlinks, and history. These domains are rebuilt with new content and hosted separately, often using different IP addresses, hosting providers, themes, and ownership details to make them appear unrelated. Within the content published on these sites, links are strategically placed that point to the main website the owner wants to rank higher. By doing this, the owner attempts to pass link equity (also known as “link juice”) from the PBN sites to the target website.
The purpose of a PBN is to give the impression that the target website is naturally earning links from multiple independent sources. If done effectively, this can temporarily improve keyword rankings, increase organic visibility, and drive more traffic from search results.