Console environment configuration for a testing workstation

Configuring the console on our example Debian testing workstation/desktop machine

Author: Francesco Poli
Contact: invernomuto@paranoici.org
Version: 0.53
Copyright: Expat license
Notice:

Copyright (c) 2007-2024 Francesco Poli

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About this document
Web form HyperText Markup Language
Source form reStructuredText
Web stylesheet Cascading StyleSheets
Build directives Makefile

Contents

Summary of previous episodes

In another document (HTML, reST) you saw some things to tweak on our example Debian testing workstation/desktop box, right after its installation. Now that the new system is up-to-date and reasonably hardened, you can customize it in order to fit your needs. If your tastes for the console environment are similar to mine, go on reading...

Shell customization

The default shell in a Debian system is GNU Bash. Let's customize the shell environment for root and for the regular user, as well.

First of all, a useful extension is the following package:

# aptitude install bash-completion

For the root user, edit /root/.bashrc. Add the following lines:

# store 1000 commands in history, but don't put duplicate lines
export HISTCONTROL=ignoredups
export HISTSIZE=1000
export HISTFILESIZE=1000

# append to the history file, don't overwrite it
shopt -s histappend

Modify the prompt line so that it looks like:

export PS1='\[\e[1m\]\u@\h \W \$ \[\e[0m\]'

and uncomment the lines that set safer aliases for potentially dangerous commands:

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

Finally add the following lines:

# set editor for fc builtin
export FCEDIT="vim"

For the regular user, edit ~/.bashrc. Change the history configuration into:

# store 1000 commands in history, but don't put duplicate lines
export HISTCONTROL=ignoredups
export HISTSIZE=1000
export HISTFILESIZE=1000

# append to the history file, don't overwrite it
shopt -s histappend

Change the prompt settings into comments and set the following prompt:

# set a fancy prompt
export PS1='${debian_chroot:+($debian_chroot) }\[\e[1m\]\u@\h \W \$ \[\e[0m\]'

If, like me, you do not like ls coloring, change the line:

alias ls='ls --color=auto'

into a comment:

#alias ls='ls --color=auto'

Finally add the following lines:

# set editor for fc builtin
export FCEDIT="vim"

Pagers and text editors

First of all, if it is not already installed, install a pager which is slightly more comfortable than more:

# aptitude install less

You can add the following two lines to your regular user's ~/.bashrc (and even to root's one), in order to get more data in the status line of less:

$ tail -2 ~/.bashrc
# default options for less
export LESS="-M"

Then, install a less minimalist VIM variant:

# aptitude install vim

and a useful plugin:

# aptitude install vim-vimoutliner

You can set up a good configuration file for VIM:

$ cat ~/.vimrc
" Use Vim defaults
set nocompatible

" Trust no one...
set secure

" set UTF-8 encoding
set encoding=utf-8

" Load plugin files for specific file types
filetype plugin on

" Syntax highlighting
set background=dark
syntax on

" Normally I want 8 spaces instead of a TAB
" (but an actual TAB may be obtained with CTRL+v,TAB)
set expandtab

" Indentation preferences (mainly for C and the like)
set autoindent
autocmd BufEnter *.c,*.h,*.cpp,*.hpp :set cindent
autocmd BufLeave *.c,*.h,*.cpp,*.hpp :set nocindent
set sw=4
set cino=n-2,{2,t0,+4,(0

" Highlight searched items
set hlsearch

" Indent when pasting by default
" (but <F11> toggles auto-indentation for pastes)
set nopaste
set pastetoggle=<F11>

" Enable mouse and have fun!
set mouse=a
:nmap <LocalLeader>p i<S-MiddleMouse><ESC>
:imap <S-Insert> <S-MiddleMouse>
:cmap <S-Insert> <S-MiddleMouse>
:map <MouseMiddle> <esc>"*p

" Speedup long file processing
autocmd BufEnter * :syntax sync minlines=100

" Do *not* autowrap text!
autocmd BufEnter * :set fo-=tc

" Set shell-like tab completion
set wildmode=longest,list:longest,list:full

The above quoted .vimrc can be used for your regular user and for root, as well.

If you want to enable the vimoutliner plugin for your regular user, issue the following command:

$ vim-addons install vimoutliner

You should also tweak its configuration:

$ cat ~/.vimoutlinerrc
let g:vo_modules_load = "checkbox"
if !exists("otl_autocmds_loaded")
  let otl_autocmds_loaded = 1
  autocmd BufWinEnter *.otl :set foldlevel=0
  autocmd BufUnload *.otl :silent !savelog -q -n -p -c 8 <afile>
  autocmd BufUnload *.otl :silent !cp -af <afile>.0 <afile>
endif

In order to enhance the markdown syntax highlighting support, until bug #885936 is fixed, you may want to add the following configuration tweak for your regular user:

$ cat ~/.vim/after/syntax/markdown.vim
unlet! b:current_syntax

syn include @tex syntax/tex.vim
syn region inlmath start="\\\@<!\$ \@!" end=" \@<!\$" skip="\\\$" keepend contains=@tex
syn region dismath start="\\\@<!\$\$" end="\$\$" keepend contains=@tex

unlet! b:current_syntax

syn include @yamlTop syntax/yaml.vim
syn region yamlmetadata start="\%^---$\|^\s*\_^---$" end="^---$\|^\.\.\.$" keepend contains=@yamlTop

let b:current_syntax = "markdown"

Obviously, you want VIM to be the system-wide default text editor! Consequently, issue the following the command:

# update-alternatives --config editor
There are 3 choices for the alternative editor (providing /usr/bin/editor).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /bin/nano            40        auto mode
  1            /bin/nano            40        manual mode
  2            /usr/bin/vim.basic   30        manual mode
  3            /usr/bin/vim.tiny    10        manual mode

Press enter to keep the current choice[*], or type selection number:

and enter "2" to select /usr/bin/vim.basic as default editor. Please note that, in case a regular user needed a different default editor, he/she can always add the following two lines to his/her own ~/.bashrc:

export EDITOR=preferrededitor
alias editor=$EDITOR

where preferrededitor should be substituted with his/her editor of choice.

Obviously, you want VIM to be your regular user's selected editor, when invoking sensible-editor (from package sensible-utils):

$ select-editor

Select an editor.  To change later, run 'select-editor'.
  1. /usr/bin/vim.gtk3
  2. /bin/nano        <---- easiest
  3. /usr/bin/vim.basic
  4. /usr/bin/vim.tiny

Choose 1-4 [2]: 1
$ cat ~/.selected_editor
# Generated by /usr/bin/select-editor
SELECTED_EDITOR="/usr/bin/vim.gtk3"

Please note that, in case you're not familiar at all with VIM, and you want to start learning how to use it, you may issue the following command:

$ vimtutor

and read through the nice interactive tutorial.

Utilities

Install a nice command to visualize directory subtrees:

# aptitude install tree

Also, install a little program to check the freeness of your system:

# aptitude install check-dfsg-status

Then, install a useful command scheduler:

# aptitude install at

Sometimes you need to measure CPU time used by a command; the following is a feature richer replacement for the corresponding GNU Bash builtin:

# aptitude install time

Just in case you come into contact with non-UTF-8 filenames:

# aptitude install convmv

A powerful command to mass-rename files:

# aptitude install rename

If it was already installed, mark it as manually installed:

# aptitude unmarkauto rename

A tool to monitor hardware health:

# aptitude install lm-sensors

In order to access more sensors, load the following kernel module:

# modprobe nct6775

In order to have this module automatically loaded at boot, create the following file:

# echo nct6775 > /etc/modules-load.d/lm-sensors_local.conf

Another tool that could be useful to get information about the CPU of the workstation is:

# aptitude install cpuid

Also, install a useful approximate GREP utility:

# aptitude install tre-agrep

Then, install a helper tool for locales:

# aptitude install localehelper

and a calendar display program:

# aptitude install ncal

Dictionaries and spell checking

Install a useful command-line online dictionary client:

# aptitude install dict

Moreover, install a spell checker:

# aptitude install ispell

Then install some other appropriate dictionaries:

# aptitude install iamerican ibritish iitalian ingerman

Finally, install some wordlists (that should be already installed for cracklib):

# aptitude install wamerican wbritish witalian wngerman

Console mouse support

Activate mouse support for the console environment:

# aptitude install gpm

Calculators

Install some useful text interface calculators:

# aptitude install dc calc

and a unit converter:

# aptitude install units

Fortune

Install the well-known fortune program, which displays epigrams on demand (it may be useful when you feel a bit sad or bored...):

# aptitude install fortunes

With this, you have the basic fortune cookie database. Install some additional collections:

# aptitude install fortunes-bofh-excuses fortunes-debian-hints

You can also install some non-english fortune collections:

# aptitude install fortunes-it

and even offensive fortunes:

# aptitude install fortunes-it-off

Debian documentation

Some documents which is good having always handy:

# aptitude install doc-debian

File comparison and conversion

Install the following word-by-word text file comparison tool:

# aptitude install wdiff

and the following new line delimiter conversion tools:

# aptitude install tofrodos

Moreover, you may want to install the following in-depth file/archive/directory comparison tool:

# aptitude --without-recommends install diffoscope python3-tlsh+M

Archive file management

Install the following multi-format archive extraction tool:

# aptitude install unar

Console fonts

Make sure the following packages are installed:

# aptitude install console-setup kbd

If they were already there, you can mark them as manually installed:

# aptitude unmarkauto console-setup kbd

Then configure the console:

# dpkg-reconfigure console-setup

You'll be asked to select the encoding to use on the console: choose "UTF-8". Then choose "Latin1 and Latin5" as character set to support, "VGA" as font for the console, and "8x16" as font size.

Finally, configure the keyboard:

# dpkg-reconfigure keyboard-configuration

Choose "Generic 104-key PC" as keyboard model, "English (US) - English (US, euro on 5)" as keyboard layout, "The default for the keyboard layout" as AltGr key, and "Menu key" as compose key; answer "No", if asked whether Control+Alt+Backspace should terminate the X server.

If you want to make these settings immediately active (without having to reboot the system), you can issue the following command on the console:

# setupcon

Large text display

Install the following package:

# aptitude install toilet

Message of the day

Prepare a little script to customize the banner that is shown when a user logs in to the console:

$ mkdir -p ~/bin
$ cat ~/bin/create-motd.sh
#!/bin/sh

center()
{
    sed -e 's/^ *// ; s/ *$// ; :loop  s/^.\{1,78\}$/ & / ; t loop ; s/ *$//'
}

NUMBER_OF_DASHES=76


echo

SEQ_DASHES=`seq $NUMBER_OF_DASHES`
DASHES=`for N in $SEQ_DASHES ; do echo -n - ; done`
echo $DASHES | center

echo

MYHOSTNAME=`hostname`
echo $MYHOSTNAME | toilet -f future | center

echo

echo "Welcome to $MYHOSTNAME" | center
echo "Debian GNU/Linux" | center

echo

echo $DASHES | center

echo

and set proper permissions:

$ chmod u+x ~/bin/create-motd.sh

You can use this script to create a customized MOTD:

$ create-motd.sh > /tmp/motd

If you are satisfied with the result, you can use it as /etc/motd:

# cat /tmp/motd > /etc/motd

Text colorizing

Install the following simple and useful package:

# aptitude install clog

Serial console connection

If you need to connect to a serial console through a serial null-modem cable, you may want to install the following package:

# aptitude install picocom

The users that need to connect to a serial console have to be added to the dialout group:

# adduser $USER dialout

where $USER should be substituted with the actual username.

Socket connection

If you need to handle sockets and the like, you may want to install the following package:

# aptitude install socat

Configuration file parsing

Install an INI-style configuration file parser:

# aptitude install confget

Conclusions

Now the system has a reasonably comfortable console. Next step is configuring the desktop environment. More details in a separate document (HTML, reST).