secciones

Pequeño selector de sesiones para .ssh/config

Un pequeño selector de sesiones para ssh, por si a alguien le pudiese ser útil. Sirve para seleccionar fácilmente la máquina a la que queremos conectarnos de entre las que tenemos configuradas en .ssh/config.

Es una sencilla función para bash, simplemente añadirla a .bashrc:

hosts() {
  local host_list=`grep "Host .*$1.*" $HOME/.ssh/config | awk '{print $2}' | sort `
  clear
  local result=$(DIALOGRC="$HOME/.dialogrc_hosts" dialog --clear --output-fd 1 --no-items --menu "Host" 0 0 0 $host_list)
  clear
  if [[ ! -z $result ]]
  then
    ssh $result
  fi
}

Una vez instalada la función, podemos ejecutar hosts para obtener un diálogo donde elegir el host al que nos queremos conectar:

Diálogo 12

Podemos filtrar el listado de elementos que se nos muestra, por ejemplo ejecutando hosts bbdd:

Diálogo 2

Finalmente, si preferimos que el diálogo se muestre sin colores, crear este fichero .dialogrc_hosts en el directorio del usuario:

# Set aspect-ration.
aspect = 0

# Set separator (for multiple widgets output).
separate_widget = ""

# Set tab-length (for textbox tab-conversion).
tab_len = 0

# Make tab-traversal for checklist, etc., include the list.
visit_items = OFF

# Shadow dialog boxes? This also turns on color.
use_shadow = OFF

# Turn color support ON or OFF
use_colors = ON

# Screen color
screen_color = (BLACK,BLACK,OFF)

# Shadow color
shadow_color = (BLACK,BLACK,OFF)

# Dialog box color
dialog_color = (BLACK,WHITE,OFF)

# Dialog box title color
title_color = (BLACK,WHITE,OFF)

# Dialog box border color
border_color = (BLACK,WHITE,OFF)

# Active button color
button_active_color = (WHITE,BLACK,ON)

# Inactive button color
button_inactive_color = dialog_color

# Active button key color
button_key_active_color = button_active_color

# Inactive button key color
button_key_inactive_color = (BLACK,WHITE,OFF)

# Active button label color
button_label_active_color = (WHITE,BLACK,OFF)

# Inactive button label color
button_label_inactive_color = (BLACK,WHITE,OFF)

# Input box color
inputbox_color = dialog_color

# Input box border color
inputbox_border_color = dialog_color

# Search box color
searchbox_color = dialog_color

# Search box title color
searchbox_title_color = title_color

# Search box border color
searchbox_border_color = border_color

# File position indicator color
position_indicator_color = title_color

# Menu box color
menubox_color = dialog_color

# Menu box border color
menubox_border_color = border_color

# Item color
item_color = dialog_color

# Selected item color
item_selected_color = button_active_color

# Tag color
tag_color = title_color

# Selected tag color
tag_selected_color = button_label_active_color

# Tag key color
tag_key_color = button_key_inactive_color

# Selected tag key color
tag_key_selected_color = (WHITE,BLACK,ON)

# Check box color
check_color = dialog_color

# Selected check box color
check_selected_color = button_active_color

# Up arrow color
uarrow_color = (GREEN,WHITE,ON)

# Down arrow color
darrow_color = uarrow_color

# Item help-text color
itemhelp_color = (WHITE,BLACK,ON)

# Active form text color
form_active_text_color = button_active_color

# Form text color
form_text_color = (WHITE,BLACK,ON)

# Readonly form item color
form_item_readonly_color = (BLACK,WHITE,ON)

# Dialog box gauge color
gauge_color = title_color

# Dialog box border2 color
border2_color = dialog_color

# Input box border2 color
inputbox_border2_color = dialog_color

# Search box border2 color
searchbox_border2_color = dialog_color

# Menu box border2 color
menubox_border2_color = dialog_color

Utiliza la utilidad dialog por lo que es necesario instalarla desde nuestro gestor de paquetes si no está ya instalada.

Anterior: Ejemplo y análisis de uso de GPT-3: Extraer fechas de texto libre Siguiente: Mini Curso: Pair Programming with a Large Language Model