[HowTo] Default Terminal to Clear Output upon File Close

Status
Not open for further replies.

zoomzoom

Guru
Joined
Sep 6, 2015
Messages
677
Updated 2018.08.05: Added xterm-256color info

FreeBSD, by default, keeps file output on screen after a file has been closed, which is the opposite of how xterm operates in Linux, and if one prefers the Linux style of xterm, which clears file output from the screen once the file has been closed, perform the following:

Solution 1 (Recommended)

Create & apply a .termcap user file:
  1. ~/.termcap
    1. nano ~/.termcap
    2. Copy, then right click in the terminal to paste:
      Code:
      xterm|X11 terminal emulator:\
      	:tc=xterm-clear:
      
      xterm-256color|xterm with 256 colors and clear:\
      	:Co#256:pa#32767:\
      	:AB=\E[48;5;%dm:AF=\E[38;5;%dm:tc=xterm-clear:\
      	:te=\E[2J\E[?47l\E8:ti=\E7\E[?47h::tc=xterm-clear:\
      	:tc=xterm-new:tc=xterm-clear:
      
    3. Save & exit: [CTRL]+ [X], [Y], press [ENTER]

  2. ~/.profile
    1. nano ~/.profile
    2. Add: TERMCAP=$(< ${HOME}/.termcap); export TERMCAP
    3. Save & exit: [CTRL]+ [X], [Y], press [ENTER]

  3. Reload terminal to apply: source ~/.cshrc

See termcap(5) man page for additional info
See this for xterm-256color difference, this for defining :te & :ti, and this for defining :tc
Solution 2

Modify /usr/share/misc/termcap
  1. nano /usr/share/misc/termcap
    1. xterm
      1. [CTRL]+ [W], type: xterm|, press [ENTER]
        • This should bring you to line 3013
          Code:
          3013:  xterm|X11 terminal emulator:\
          3014:	  :tc=xterm-new:
          3015:  #   :tc=xterm-r6:
          
      2. Change line 3014: :tc=xterm-clear:

    2. xterm-256color
      1. [CTRL]+ [W], type: xterm alias 3, press [ENTER]
        • This should bring you to line 2884
          Code:
          2884:  xterm-256color|xterm alias 3:\
          2885:	  :Co#256:pa#32767:\
          2886:	  :AB=\E[48;5;%dm:AF=\E[38;5;%dm:tc=xterm-new:
          
      2. Change line 2886: :AB=\E[48;5;%dm:AF=\E[38;5;%dm:tc=xterm-clear:\
      3. Add line 2887: :te=\E[2J\E[?47l\E8:ti=\E7\E[?47h::tc=xterm-clear:\
      4. Add line 2888: :tc=xterm-new:tc=xterm-clear:

  2. Save & exit: [CTRL]+ [X], [Y], press [ENTER]
  3. Rebuild termcap-database: cap_mkdb /usr/share/misc/termcap

It also appears [HOME], [END], & [DELETE] keys lost their bindings in FreeNAS 11, and while these can be added back via ~/.termcap, it's simpler to add them to ~/.cshrc

Modify ~/.cshrc
  1. nano ~/.cshrc
  2. Copy, then paste to prompt section:
    Code:
    	bindkey "\e[1~" beginning-of-line
    	bindkey "\e[3~" delete-char
    	bindkey "\e[4~" end-of-line
    
    • Example:
      Code:
      	# Shell #
      #--------------------------------------
      if ($?prompt) then
        set prompt		= "[%{\033[34m%}%N%{\033[0m%}%{\033[32m%}@%{\033[0m%}%{\033[34m%}%m%{\033[0m%}] %{\033[34m%} %~$
        set promptchars   = "%#"
      
        set filec
        set history	   = 1000
        set savehist	  = (1000 merge)
        set autolist	  = ambiguous
        set mail		  = (/var/mail/$USER)
      
        set autoexpand
        set autorehash
      
        bindkey "\e[1~" beginning-of-line
        bindkey "\e[3~" delete-char
        bindkey "\e[4~" end-of-line
      
        if ( $?tcsh ) then
      	bindkey "^W"	backward-delete-word
      	bindkey -k up   history-search-backward
      	bindkey -k down history-search-forward
        endif
      endif
      
  3. Save & exit: [CTRL]+ [X], [Y], press [ENTER]
  4. Reload terminal: source ~/.cshrc
 
Last edited:

m0nkey_

MVP
Joined
Oct 27, 2015
Messages
2,739
Just so it survives software upgrades, add this to the .termcap file of your users home directory instead. :)
 

zoomzoom

Guru
Joined
Sep 6, 2015
Messages
677
I added instructions on a user ~/.termcap, however does the shell auto load it first prior to going to the main termcap file, or does an export parameter need to be added to ~/.profile or /etc/profile?
 
Last edited:

zoomzoom

Guru
Joined
Sep 6, 2015
Messages
677
Updated with the missing piece, which is the editing of ~/.profile.
 

zoomzoom

Guru
Joined
Sep 6, 2015
Messages
677
Updated with xterm-256color info
 
Status
Not open for further replies.
Top