Skip to content

Instantly share code, notes, and snippets.

@merces
Created March 6, 2015 05:56
Show Gist options
  • Save merces/36ce6e9602c163cf129e to your computer and use it in GitHub Desktop.
Save merces/36ce6e9602c163cf129e to your computer and use it in GitHub Desktop.
A minimalist shell skeleton
#!/bin/bash
echo "bemvindo ao minibash
comandos disponiveis: listar sair"
while :; do
read -p '$ ' cmd
case $cmd in
listar)
ls ;;
sair)
exit ;;
'')
continue ;;
*)
echo $cmd: comando invalido ;;
esac
done
@wesleyleite
Copy link

Rapaz,

Podia jurar que poderia mandar um pull request aqui "mas não", acho que um tab com autocomplet seria perfeito nessa solução, ajuda a lembrar dos comandos.. ;)

!/bin/bash

declare -a comandos
comandos=('listar'\
'sair')

echo "bemvindo ao minibash
use TAB para ver comandos disponiveis"

set -o vi
bind 'TAB:dynamic-complete-history'

history -s "${comandos[@]}"

while :; do
read -e -p '$ ' cmd
case $cmd in
listar)
ls ;;
sair)
exit ;;
'')
continue ;;
*)
echo $cmd: comando invalido ;;
esac
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment