From a4fbd124da8fc2bf65058ca971efb64cefa87fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=2E=20S=C3=A1nchez?= Date: Thu, 25 May 2023 03:24:33 -0600 Subject: [PATCH] Reemplazo de espacios por tabulaciones --- functions_korn/admin_prompt | 7 +++---- functions_korn/count | 15 ++++++++------- functions_korn/countl | 11 +++++------ functions_korn/get_branch | 13 ++++++------- functions_korn/get_dir | 5 ++--- functions_korn/man | 19 +++++++++---------- functions_korn/mkcd | 7 +++---- functions_korn/prompt | 7 +++---- functions_korn/rman | 14 +++++++------- functions_korn/ver | 2 +- functions_korn/which_sudo | 19 ++++++++++--------- 11 files changed, 57 insertions(+), 62 deletions(-) diff --git a/functions_korn/admin_prompt b/functions_korn/admin_prompt index 1de7033..7f012db 100644 --- a/functions_korn/admin_prompt +++ b/functions_korn/admin_prompt @@ -1,9 +1,8 @@ # Añadir esta configuración en /root/.profile para personalizar el prompt para root -function admin_prompt -{ - [[ $PWD == $HOME ]] && dir="~" || dir="${PWD#*/}" - print "${YELLOW}[$dir] ${GREEN}#${RED} " +function admin_prompt { + [[ $PWD == $HOME ]] && dir="~" || dir="${PWD#*/}" + print "${YELLOW}[$dir] ${GREEN}#${RED} " } PS1="\$(admin_prompt) " diff --git a/functions_korn/count b/functions_korn/count index 2b0dd0a..1dd5280 100644 --- a/functions_korn/count +++ b/functions_korn/count @@ -1,11 +1,12 @@ # Contar archivos o directorios en el directorio # Esto funciona pasando la salida del glob a la función y luego contando el número de argumentos. -function count -{ - # Uso: - # count /path/to/dir/* -> Total (archivos y directorios) - # count /path/to/dir/*/ -> Total de directorios - - [[ -e $1 ]] && print "$#" || print 0 +function count { + if [[ $# -eq 0 ]]; then + print "count /path/to/dir/* -> Total (archivos y directorios)" >&2 + print "count /path/to/dir/*/ -> Total de directorios" >&2 + return 1 + elif + [[ -e $1 ]] && print "$#" || print 0 + fi } diff --git a/functions_korn/countl b/functions_korn/countl index df9c5e5..07acaaa 100644 --- a/functions_korn/countl +++ b/functions_korn/countl @@ -2,12 +2,11 @@ function countl { - lines=0 + lines=0 - while IFS= read -r line || [[ -n $line ]]; do - # lines=$((lines+1)) is slower than ((lines=lines+1)) - ((lines=lines+1)) - done < "$1" + while IFS= read -r line || [[ -n $line ]]; do + ((lines=lines+1)) + done < "$1" - printf '%s\n' "$lines" + printf '%s\n' "$lines" } diff --git a/functions_korn/get_branch b/functions_korn/get_branch index 564b732..e5d9264 100644 --- a/functions_korn/get_branch +++ b/functions_korn/get_branch @@ -1,11 +1,10 @@ # Mostrar rama actual en directorios de git -function get_branch -{ - BRANCH=$(git rev-parse --abbrev-ref HEAD 2> /dev/null) - if [[ ! -z ${BRANCH} ]]; then - print "${BRANCH}" - fi +function get_branch { + BRANCH=$(git rev-parse --abbrev-ref HEAD 2> /dev/null) + if [[ ! -z ${BRANCH} ]]; then + print "${BRANCH}" + fi - unset BRANCH + unset BRANCH } diff --git a/functions_korn/get_dir b/functions_korn/get_dir index a852af2..57d4d8a 100644 --- a/functions_korn/get_dir +++ b/functions_korn/get_dir @@ -1,6 +1,5 @@ # Mostrar directorio de trabajo actual -function get_dir -{ - printf '%s\n' ${PWD/$HOME/\~} +function get_dir { + printf '%s\n' ${PWD/$HOME/\~} } diff --git a/functions_korn/man b/functions_korn/man index e2856a7..672b1b6 100644 --- a/functions_korn/man +++ b/functions_korn/man @@ -1,13 +1,12 @@ # Mostrar los manuales de los programa con color -function man -{ - LESS_TERMCAP_mb=$(printf %b "\033[1;31m") \ - LESS_TERMCAP_md=$(printf %b "\033[1;31m") \ - LESS_TERMCAP_me=$(printf %b "\033[0m") \ - LESS_TERMCAP_se=$(printf %b "\033[0m") \ - LESS_TERMCAP_so=$(printf %b "\033[1;44;33m") \ - LESS_TERMCAP_ue=$(printf %b "\033[0m") \ - LESS_TERMCAP_us=$(printf %b "\033[1;32m") \ - command man -a "$@" +function man { + LESS_TERMCAP_mb=$(printf %b "\033[1;31m") \ + LESS_TERMCAP_md=$(printf %b "\033[1;31m") \ + LESS_TERMCAP_me=$(printf %b "\033[0m") \ + LESS_TERMCAP_se=$(printf %b "\033[0m") \ + LESS_TERMCAP_so=$(printf %b "\033[1;44;33m") \ + LESS_TERMCAP_ue=$(printf %b "\033[0m") \ + LESS_TERMCAP_us=$(printf %b "\033[1;32m") \ + command man -a "$@" } diff --git a/functions_korn/mkcd b/functions_korn/mkcd index fec8256..1a35a04 100644 --- a/functions_korn/mkcd +++ b/functions_korn/mkcd @@ -1,7 +1,6 @@ # Crear un directorio y cambiar a él -function mkcd -{ - mkdir -p -- "$1" || return - cd -P -- "$1" +function mkcd { + mkdir -p -- "$1" || return + cd -P -- "$1" } diff --git a/functions_korn/prompt b/functions_korn/prompt index 6b4f40f..675b2fa 100644 --- a/functions_korn/prompt +++ b/functions_korn/prompt @@ -1,9 +1,8 @@ # Prompt para usuario normal -function prompt -{ - print "${GREEN}${PWD/$HOME/\~} ${CYAN}$(get_branch)" - print "${RED}-> ${YELLOW}$ ${NORM}" +function prompt { + print "${GREEN}${PWD/$HOME/\~} ${CYAN}$(get_branch)" + print "${RED}-> ${YELLOW}$ ${NORM}" } PS1="\$(prompt) " diff --git a/functions_korn/rman b/functions_korn/rman index fd7a3bc..e85b169 100644 --- a/functions_korn/rman +++ b/functions_korn/rman @@ -1,11 +1,11 @@ # Consultar manuales de programa remotos rman() { - if command -v lynx >/dev/null; then - lynx https://man.voidlinux.org/x86_64/"$@" - return 0 - else - print "Instale el programa lynx" - return 1 - fi + if command -v lynx >/dev/null; then + lynx https://man.voidlinux.org/x86_64/"$@" + return 0 + else + print "Instale el programa lynx" + return 1 + fi } diff --git a/functions_korn/ver b/functions_korn/ver index f440a9b..f2556e3 100644 --- a/functions_korn/ver +++ b/functions_korn/ver @@ -1,5 +1,5 @@ # Consultar qué versión de shell korn se tiene en el sistema ver() { - printf '%s\n' "Korn Shell: ${KSH_VERSION:-desconocida}" + printf '%s\n' "Korn Shell: ${KSH_VERSION:-desconocida}" } diff --git a/functions_korn/which_sudo b/functions_korn/which_sudo index 114e821..57eb823 100644 --- a/functions_korn/which_sudo +++ b/functions_korn/which_sudo @@ -1,13 +1,14 @@ # Función que se encarga de determinar qué programa usar para escalar # permisos de administrador -function which_sudo -{ - if command -v sudo >/dev/null && sudo -l | grep -q -e ' ALL$' -e xbps-install; then - print sudo - elif command -v doas >/dev/null && [ -f /etc/doas.conf ]; then - print doas - elif [[ $(id -u) != 0 ]]; then - print su - fi +function which_sudo { + if [[ $(id -u) == 0 ]]; then + return + elif command -v sudo >/dev/null && id | grep -q wheel; then + print sudo + elif command -v doas >/dev/null && [ -f /etc/doas.conf ]; then + print doas + else + print su + fi }