De Pergunte ao Ubuntu :
![](https://i.stack.imgur.com/LY6hT.png)
VerifiqueolinkAskUbuntuacimaparaobtercomentáriosepossivelmentenovasrespostasdeoutrosusuários.
now
scriptbash
Otrabalhopesadoéocomponenteinicialquemostraisso:
$nowWeatherreport:EdmontonMarch2018┌────────────────────────────┐SuMoTuWeThFrSa│┏━┓╺┓┏━┓┏━┓┏━┓┏┳┓│\/Sunny123│┃┃┃┃╹┏━┛┗━┫┣━┛┃┃┃│.-.-23--14°C45678910│┗━┛╺┻╸╹┗━╸┗━┛╹╹╹│―()―↘22km/h11121314151617└────────────────────────────┘'-’14km18192021222324/\0.9mm25262728293031
Sim,realmenteé-14emEdmontoneparece-23.Umbommomentoparapassarolongofimdesemanadentrodorecém-chegadoTombRaider2013!TalvezescovaresseresumoparasemudarparaVancouverouMontreal...
Aquiestáocódigo:
#!/bin/bash
# NAME: now
# PATH: $HOME/bin
# DESC: Display current weather, calendar and time
# CALL: Called from terminal or ~/.bashrc
# DATE: Apr 6, 2017. Modified: Mar 30, 2018.
# NOTE: To display all available toilet fonts use this one-liner:
# for i in ${TOILET_FONT_PATH:=/usr/share/figlet}/*.{t,f}lf; do j=${i##*/}; toilet -d "${i%/*}" -f "$j" "${j%.*}"; done
# Setup for 92 character wide terminal
DateColumn=34 # Default is 27 for 80 character line, 34 for 92 character line
TimeColumn=61 # Default is 49 for " " " " 61 " " " "
#--------- WEATHER ----------------------------------------------------------
# Current weather, already in color so no need to override
echo " "
# Replace Edmonton with your city name, GPS, etc. See: curl wttr.in/:help
curl wttr.in/Edmonton?0 --silent --max-time 3
# Timeout #. Increase for slow connection---^
echo " "
echo " " # Pad with blank lines for calendar & time to fit
#--------- DATE -------------------------------------------------------------
# calendar current month with today highlighted.
# colors 00=bright white, 31=red, 32=green, 33=yellow, 34=blue, 35=purple,
# 36=cyan, 37=white
tput sc # Save cursor position.
# Move up 9 lines
while [ $((++i)) -lt 10 ]; do tput cuu1; done
# Depending on length of your city name and country name you will:
# 1. Comment out next three lines of code. Uncomment fourth code line.
# 2. Change subtraction value and set number of print spaces to match
# subtraction value. Then place comment on fourth code line.
Column=$(($DateColumn - 10))
tput cuf $Column # Move x column number
printf " " # Blank out ", country" with x spaces
#tput cuf $DateColumn # Position to column 27 for date display
# -h needed to turn off formating: https://sobrelinux.info/questions/32733/bash-substring-stringoffsetlength-error"%d")
# Prefix with space when length < 2
if [[ ${#Today} < 2 ]] ; then
Today=" "$Today
fi
printf "3[32m" # color green -- see list above.
while IFS= read -r Cal; do
printf "$Cal"
if [[ $CalLineCnt > 2 ]] ; then
# See if today is on current line & invert background
tput cub 22
for (( j=0 ; j <= 18 ; j += 3 )) ; do
Test=${Cal:$j:2} # Current day on calendar line
if [[ "$Test" == "$Today" ]] ; then
printf "3[7m" # Reverse: [ 7 m
printf "$Today"
printf "3[0m" # Normal: [ 0 m
printf "3[32m" # color green -- see list above.
tput cuf 1
else
tput cuf 3
fi
done
fi
tput cud1 # Down one line
tput cuf $DateColumn # Move 27 columns right
CalLineCnt=$((++CalLineCnt))
done < /tmp/terminal
printf "3[00m" # color -- bright white (default)
echo ""
tput rc # Restore saved cursor position.
#-------- TIME --------------------------------------------------------------
tput sc # Save cursor position.
# Move up 9 lines
i=0
while [ $((++i)) -lt 10 ]; do tput cuu1; done
tput cuf $TimeColumn # Move 49 columns right
# Do we have the toilet package?
if hash toilet 2>/dev/null; then
echo " "$(date +"%I:%M %P")" " | \
toilet -f future --filter border > /tmp/terminal
# Do we have the figlet package?
elif hash figlet 2>/dev/null; then
echo $(date +"%I:%M %P") | figlet > /tmp/terminal
# else use standard font
else
echo $(date +"%I:%M %P") > /tmp/terminal
fi
while IFS= read -r Time; do
printf "3[01;36m" # color cyan
printf "$Time"
tput cud1 # Up one line
tput cuf $TimeColumn # Move 49 columns right
done < /tmp/terminal
tput rc # Restore saved cursor position.
exit 0
Pré-requisitos
Para a exibição sofisticada, você precisa instalar o toilet
:
sudo apt install toilet
Para outra exibição sofisticada (mas não tão extravagante) instale figlet
:
sudo apt install figlet
Caso contrário, a hora será exibida na fonte "normal".
Tempo
O tempo é fornecido pelo comando curl wttr.in/cityname?0
. No seu terminal use: curl wttr.in/:help
para detalhes adicionais.
Tempo: altere o nome da cidade
Você desejará modificar esta seção do código e alterar Edmonton
para o nome da sua cidade:
# Replace Edmonton with your city name, GPS, etc. See: curl wttr.in/:help
curl wttr.in/Edmonton?0 --silent --max-time 3
# Timeout #. Increase for slow connection---^
O Unicode é compatível com nomes de cidades como /Москва
(Moscou). Cartas de aeroporto são suportadas, como YEG
para Edmonton.
Tempo: remover o nome do país
Quando o terminal está definido para 92 caracteres de largura, o clima é exibido como "Edmonton, Canadá". que é muito longo para o meu gosto:
![](https://i.stack.imgur.com/pl1P7.png)
Pioraindaquandooterminalédefinidocom80caracterespadrãodelargura:
![](https://i.stack.imgur.com/43AWN.png)
Paracontornaroproblema,"Countryname" está em branco na tela com este código:
# Depending on length of your city name and country name you will:
# 1. Comment out next three lines of code. Uncomment fourth code line.
# 2. Change subtraction value and set number of print spaces to match
# subtraction value. Then place comment on fourth code line.
Column=$(($DateColumn - 10))
tput cuf $Column # Move x column number
printf " " # Blank out ", country" with x spaces
#tput cuf $DateColumn # Position to column 27 for date display
Se você precisar de ajuda com essa parte do script, poste um comentário abaixo para obter ajuda.
Ajustes de largura da tela do terminal
Ajuste o espaçamento para a largura da tela do terminal, alterando:
# Setup for 92 character wide terminal
DateColumn=34 # Default is 27 for 80 character line, 34 for 92 character line
TimeColumn=61 # Default is 49 for " " " " 61 " " " "
Juntando tudo em ~/.bashrc
Edite seu arquivo ~/.bashrc
e adicione essas linhas ao final:
# Splash Calendar and time
now
# ASCII Linux distribution display
screenfetch
Salve as alterações do arquivo '~ / .bashrc ".
Para exibir as informações do Ubuntu, você precisa de screenfetch
:
sudo apt install screenfetch
Existem pacotes de exibição semelhantes a screenfetch
, por isso compre!
Se você quiser o mesmo prompt de comando com "─────────" linha divisória entre os comandos, altere estas linhas:
if [ "$color_prompt" = yes ]; then
PS1='───────────────────────────────────────────────────────────────────────────────────────────
${debian_chroot:+($debian_chroot)}\[3[01;32m\]\u@\h\[3[00m\]:\[3[01;34m\]\w\[3[00m\]\$ '
else
PS1='───────────────────────────────────────────────────────────────────────────────────────────
${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
Observe que o comprimento da linha separadora coincide com a largura de screenfetch
de saída. Nesse caso, ele tem 92 caracteres de largura e gnome-terminal
de preferências são definidas de acordo.