• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Share your .tcshrc file


Well-Known Member

Thanks: 249
Messages: 435

Also found few very usable ~/.tcshrc options, that are not described in this theme yet.
To notify you when someone logs in or out,

	set watch = (0 any any)
to ~/tcshrc.

And to add the date to the history command,

	set histfile = "$HOME/.csh_history"
	set savehist = (5000 merge)
	[u][b]set history = (5000 "%h %D-%W-%Y %T %R\n")[/b][/u]
to ~/tcshrc.


Well-Known Member

Thanks: 249
Messages: 435

Here is my full ~/.tcshrc, with few examples, may be it will be interesting for someone,
Personally I would be very happy if I found post like this when I started with tcsh.
It's tested and seems to be working fine, few things were taken from shells/tcshrc,
others from tcsh(1) and tcsh.org manuals, or from few some other posts, on the web…

It has some interesting features, for example:
cd is an ailas of pushd,
so every time you 'cd' into directory, directory saves to the directory stack,
so, for example, you can use popd to to return to the previous directory

(to disable printing of the directory stack use set pushdsilent.)
(to clean the directory stack use dirs -c, to add current dir and list — dirs -l [learn more]).
But if you don't need to save directory to directory stack,
just don't use cd, "implicitcd" option is enabled,
so you do not need to use cd to change directories,
just type path

Also " cd" without arguments takes you to your home dir, because "pushdtohome" option is enabled.

# update and save history after each command
alias postcmd	'history -S'
It works like "setopt SHARE_HISTORY" in zsh, it should be placed at the end of ~/.tcshrc.

Also I use security/doas with some apps,
so I got few aliases for it,
# doas alias-es
alias vm	'doas vm'
alias ezjail	'doas ezjail-admin'
So with it I can use sysutils/vm-bhyve and sysutils/ezjail without sudo,
to manipulate bhyve virtual machines and jails. To make it possible you need to install security/doas,
also you need to create /usr/local/etc/doas.conf:
permit nopass keepenv :wheel cmd vm
permit nopass keepenv :wheel cmd ezjail-admin
your user should be in a wheel group — # pw groupmod wheel -m username
(relogin after this command, to update your groups),

"autorehash" option is set to "always", so you don't need to type rehash manually after each package installation,
because the list of available commands will be rebuilt, for each command completion or spelling correction attempt.

"LSCOLORS" environment variable sets colors in cli apps, like /bin/ls,
you can create your own color set here.

"correct" option is set, so spelling-correction works,
you can edit your "correct" message with (it is a default value)
set prompt3 = "CORRECT>%R (y|n|e|a)?"

"listjobs" option is set, so all active jobs will be listed when your current job is suspended (use ctrl+z to suspend).

With "listflags" option, you can add flags to "autolist" (ls-F, builtin ls), which is called by TAB key,
for example,
set listflags  = a
Full ~/.tcshrc:
# # # .tcshrc - tcsh resource script, read at beginning of execution by each shell # # #

# skip configuration if shell is not an interactive shell
if ( $?prompt3 == 0 ) exit

setenv		EDITOR		'vim'
setenv		PAGER		'less'
setenv		LESS		'-Airs'
setenv		GREP_COLOR	'1;31'
setenv		CLICOLOR	'1'
setenv		LSCOLORS	'cxfxdxbxexeafaachcagbg'

set path = ( $path $HOME/.local/bin )
set prompt = " %{\033[0;32m%}%C%{\033[0m%} %# "
set prompt3 = "	%R ? (y|n|e|a) "
set promptchars = "%#"
set history = (2000 "%h %D.%W %T %R\n")
set savehist = (2000 merge)
set histfile = "$HOME/.history"
set histdup = erase		 # erase duplicate history events
set watch = (0 any any)		 # notify when someone logs in or out
set who = "%n %a %l from %m"	 # format for watch messages
set notify			 # notification when jobs change state
set listjobs			 # all jobs are listed when a job is suspended
set implicitcd			 # change directory without cd
set symlinks = chase		 # symbolic link is expanded to the real name of the directory
set autocorrect			 # spell-word editor command is invoked automatically
set autoexpand			 # run expand-history before each completion attempt
set autolist = ambiguous	 # choices are listed only when completion fails
set autorehash = always		 # update $PATH after each completion or spelling correction attempt
set correct = cmd		 # commands are automatically spelling-corrected
set complete = enhance		 # completion ignores case and considers hyphens and underscores
set matchbeep = nomatch		 # beeps only when there is no match
set color			 # enables colors for the builtin autolist (TAB)
set rmstar			 # user is prompted before `rm *' is executed
set pushdtohome			 # pushd without arguments does `pushd ~'
#set listflags  = a		 # flags for autolist (TAB)
#set colorcat			 # enables color escape sequence for NLS message files (to make it work, you need to define COLORCAT in /usr/src/contrib/tcsh/config_f.h and recompile tcsh (rebuild world))
# format of `time' command
set time=(8 "\
Time spent in user mode       : %Us\
Time spent in kernel mode     : %Ss\
Total time                    : %Es\
CPU utilisation (percentage)  : %P\
Times the process was swapped : %W\
Times of major page faults    : %F\
Times of minor page faults    : %R")

alias cd	'pushd'
alias c		'cat'
alias q		'exit'
alias h		'history 25'
alias j		'jobs -l'
alias f		'psearch'
alias F		'find . -type f'
alias ff    	'find . -name $*'
alias p		'cd /usr/ports && cd'			 # use it like "p www/firefox"
alias grep	'grep --color'
alias gnugrep	'/usr/local/bin/grep --color'
alias g		'grep -i'
alias v		'vim'
alias .		'pwd'
alias ...	'../..'
alias ls	'ls -F'
alias la	'ls -a'
alias ll	'ls -lht'
alias l		'ls'
alias mkdir	'mkdir -p'
alias s		'sudo'
alias ss	'sudo su -'
alias stat	'stat -x'
alias date	'date +"%d-%m-%Y, %H:%M"'
alias tkill	'tmux kill-session -t'
alias cputemp	'sysctl -a | grep "dev.cpu.*.temperature"'
# doas alias-es
alias vm		'doas vm'
alias ezjail-admin	'doas ezjail-admin'

bindkey -k up history-search-backward	 # up
bindkey -k down history-search-forward	 # down
bindkey '\e[1;5A' i-search-back		 # ctrl+up
bindkey '\e[1;5B' i-search-fwd		 # ctrl+down
bindkey '\e[3~' delete-char		 # delete
bindkey '\e[1;5D' backward-word		 # ctrl+left
bindkey '\e[1;5C' forward-word		 # ctrl+right
bindkey '\e[3;3~' delete-word		 # alt+delete
bindkey '\e[1;3C' delete-word		 # alt+right
bindkey '\e[1;3D' backward-delete-word	 # alt+left
bindkey "\e[1~" beginning-of-line	 # home
bindkey "\e[4~" end-of-line		 # end
# rxvt key bindings
bindkey '\eOd' backward-word		 # ctrl+left
bindkey '\eOc' forward-word		 # ctrl+right
bindkey '\e^[[3~' delete-word		 # alt+delete
bindkey '\e^[[C' delete-word		 # alt+right
bindkey '\e^[[D' backward-delete-word	 # alt+left
bindkey "\e[7~" beginning-of-line	 # home
bindkey "\e[8~" end-of-line		 # end

# start tmux with shell
#if (! $?TMUX) exec tmux -l2

# update and save history after each command
alias postcmd	'history -S'
Last edited:


Well-Known Member

Thanks: 6
Messages: 379

finally… "csh shell history is puzzled", because of this problem I've even switched to zsh.
But it seems that new version doesn't have this problem anymore.

But I'm really missing one feature,
I want to be able to save my tcsh history after each tcsh command.
"alias precmd 'history -L; history -S'" saves, but it also adds some strange history events

UPD: Solved. It seems
if ($?prompt3) then
    alias postcmd    'history -S'     # update and save history after each command
do the job, without any issues.
Hello ILUXA!

With csh(1) you cannot remove ~ and @ symbols? And can you change with csh(1) the color of user and root? Sorry I'm very confused about this, give me a hand how to proceed with csh(1), I use csh on UFS files for FreeBSD system of 64-bit.



Thanks: 390
Messages: 1,019

Nothing special: .cshrc

set path = ( /sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin $HOME/.local/bin )

alias df   df -H
alias h       history 25
alias j       jobs -l
alias la   ls -aF
alias lf   ls -FA
alias ll   ls -lAF

if ( -X nvim ) then
   setenv   EDITOR   nvim
   alias   vi   nvim
else if (-X vi) then
   setenv   EDITOR   vi

setenv   BLOCKSIZE       M
setenv    CLICOLOR       1
setenv   PAGER           more

setenv   TERMINAL       urxvtc
setenv   PANEL_FIFO       /tmp/panel-fifo
setenv   QT_QPA_PLATFORMTHEME   qt5ct
setenv   XDG_MENU_PREFIX       lxde-

if ($?prompt) then

   set autoexpand
   set color
   set colorcat
   set filec
   set autolist    = ambiguous
   set correct    = cmd
   set history    = 2048
   set histfile    = ~/.csh_history
   set mail    = (/var/mail/$USER)
   set savehist   = (1024 merge)
   set autorehash    = always

   set grey    = "%{\033[1;30m%}"
   set red    = "%{\033[1;31m%}"
   set green    = "%{\033[1;32m%}"
   set yellow    = "%{\033[1;33m%}"
   set blue    = "%{\033[1;34m%}"
   set magenta    = "%{\033[1;35m%}"
   set cyan    = "%{\033[1;36m%}"
   set white    = "%{\033[1;37m%}"

   set end    = "%{\033[0m%}"

       if ($tty =~ ttyv*) then

           if ( $USER == root ) then
               set prompt = "\n${blue}%~ ${red}%N@%m: \n>>>${end} "
               set prompt = "\n${red}%~ ${blue}%m: \n>>>${end} "


           if ( $USER == root ) then
               set prompt = "\n${blue}%~ ${red}%N@%m: \n❱❱❱${end} "
               set prompt = "\n${red}%~ ${blue}%m: \n❱❱❱${end} "


   unset grey red green yellow blue magenta cyan white end
   if ( $?tcsh ) then
           bindkey "^[Od"       backward-word       # rxvt
           bindkey "^[Oc"       forward-word       # rxvt
           bindkey   "\e[2~"       overwrite-mode
           bindkey   "\e[3~"       delete-char
           bindkey   "\e[1;5C"   forward-word
           bindkey   "\e[1;5D"   backward-word
           bindkey   "\e[5~"       history-search-backward
           bindkey   "\e[6~"       history-search-forward
           bindkey   "^W"       backward-delete-word


Well-Known Member

Thanks: 46
Messages: 252

alias ls	ls -G
alias ls  ls -G
alias svn /usr/bin/svnlite
alias svnadmin /usr/bin/svnliteadmin
alias svnlook /usr/bin/svnlitelook
alias svnsync /usr/bin/svnlitesync
alias time  /usr/bin/time

setenv CLICOLOR 1
setenv EDITOR vim
setenv LANG hu_HU.UTF-8
setenv LC_ALL hu_HU.UTF-8
setenv LESS "-Ri"
setenv LSCOLORS GefhcxdxgXegedabagacad
setenv PAGER less
setenv PATH /sbin/:/usr/sbin/:/usr/bin:/bin:/usr/local/libexec/ccache:/home/zsolt/bin:/usr/local/bin:/sbin/:/usr/sbin/:/home/zsolt/bin:/usr/local/bin

if ($?prompt) then
  # An interactive shell -- set some stuff up

  set addsuffix
  set filec
  set history = 1000
  set savehist = (1000 merge)
  set autolist = ambiguous
  # Use history to aid expansion
  set autoexpand
  set autorehash
  set color
  set noding
  set coredumpsize = 0
  if ( $?tcsh ) then
    bindkey "^W" backward-delete-word
    bindkey -k up history-search-backward
    bindkey -k down history-search-forward

set coredumpsize=0
complete git \
  'p/1/(add commit rm status diff push pull)/' \
  'n@diff@`git status -s | sed -n "/^ M/ s,^ M ,,p"`@' \
  'n@add@`git status -s | sed -n "/^??/ s,^?? ,,p"`@' \
  'n@commit@`git status -s | sed -n "/^[A ]/ s,^...,,p" ; echo .`@' \
  'n@push@`git remote`@'

set mandir="/usr/share/man/man* /usr/local/man/man*"
set pdf="f:*.[pP][dD][fF]"

complete cd \

complete chown \

complete complete \

complete dd \
  'c/[io]f=/f/ n/*/"(if of ibs obs bs skip seek count)"/='

complete doas \
  'p@1@`sed "s,.*cmd *\([^ ]*\).*,\1," /usr/local/etc/doas.conf`@'

complete find \
  'n/-fstype/"(nfs 4.2)"/' 'n/-name/f/' \
  'n/-type/(c b d f p l s)/' \
  'n/-user/u/ n/-group/g/' \
  'n/-exec/c/' 'n/-ok/c/' \
  'n/-cpio/f/' \
  'n/-ncpio/f/' \
  'n/-newer/f/' \
  'c/-/(fstype name perm prune type user nouser group nogroup size inum atime mtime ctime exec \
    ok print ls cpio ncpio newer xdev depth daystart follow maxdepth mindepth noleaf version \
    anewer cnewer amin cmin mmin true false uid gid ilname iname ipath iregex links lname empty path \
    regex used xtype fprint fprint0 fprintf print0 printf not a and o or)/' \

complete gpart \
  'p/1/(add backup bootcode commit create delete destroy modify recover resize restore set show undo unset)/' \
  'n/add/x:-t type [-a alignment] [-b start] [-s size] [-i index] [-l label] -f flags geom/' \
  'n/backup/x:geom/' \
  'n/bootcode/x:[-b bootcode] [-p partcode -i index] [-f flags] geom/' \
  'n/commit/x:geom/' \
  'n/create/x:-s scheme [-n entries] [-f flags] provider/' \
  'n/delete/x:-i index [-f flags] geom/' \
  'n/destroy/x:[-F] [-f flags] geom/' \
  'n/modify/x:-i index [-l label] [-t type] [-f flags] geom/' \
  'n/recover/x:[-f flags] geom/' \
  'n/resize/x:-i index [-a alignment] [-s size] [-f flags] geom/' \
  'n/restore/x:[-lF] [-f flags] provider [...]/' \
  'n/set/x:-a attrib -i index [-f flags] geom/' \
  'n/show/x:[-l | -r] [-p] [geom ...]/' \
  'n/undo/x:geom/' \
  'n/unset/x:-a attrib -i index [-f flags] geom/'

complete grep \
  'c/-*A/x:<#_lines_after>/' \
  'c/-*B/x:<#_lines_before>/' \
  'c/--/(extended-regexp fixed-regexp basic-regexp regexp file ignore-case word-regexp line-regexp \
    no-messages revert-match version help byte-offset line-number with-filename no-filename quiet silent \
    text directories recursive files-without-match files-with-matches count before-context after-context \
    context binary unix-byte-offsets)/' \
  'c/-/(A a B b C c d E e F f G H h i L l n q r s U u V v w x)/' \
  'p/1/x:<limited_regular_expression>/ N/-*e/f/' \
  'n/-*e/x:<limited_regular_expression>/' \
  'n/-*f/f/' \

complete herbstclient \
  'p/*/`set cmd="${COMMAND_LINE}x"; \
    set cmd=( ${cmd:s,herbstclient,,} ); \
    set cmd_nr=${#cmd} ; \
    @ cmd_nr-- ; \
    herbstclient complete_shell ${cmd_nr} ${COMMAND_LINE:s,herbstclient,,}`/'

complete ifconfig \
  'p@1@`ifconfig -l`@' \
  'n/*/(range phase link netmask mtu vlandev vlan metric mediaopt down delete broadcast arp debug)/' \
  'c/%/j/' \
  'n/*/`ps -ax | awk '"'"'{print $1}'"'"'`/'

complete kill \
  'c/-/S/' \
  'c/%/j/' \
  'n/*/`ps -ax | awk '"'"'{print $1}'"'"'`/'

complete killall \
  'c/-/S/' \
  'c/%/j/' \
  'n/*/`ps -ax | awk '"'"'{print $5}'"'"'`/'

complete kldload \
  'n@*@`ls -1 /boot/modules/ /boot/kernel/ | awk -F/ \$NF\ \~\ \".ko\"\ \{sub\(\/\.ko\/,\"\",\$NF\)\;print\ \$NF\}`@'

complete kldunload \
  'n@*@`kldstat | awk \{sub\(\/\.ko\/,\"\",\$NF\)\;print\ \$NF\} | grep -v Name`@'

complete localc \

complete lowriter \

complete make \
  'p@1@`make -V.ALLTARGETS`@'

complete man \
  'C@*@`find ${mandir} -type f -name \*.gz | sed "s,.*/,, ; s,\.[^\.]*\.gz,,"`@'

complete mupdf \

complete okular \

complete pdflatex \

complete service \
  'c/-/(e l r v)/' \
  'p/1/`service -l`/' \
  'n/*/(start stop reload restart status rcvar onestart onestop)/'

complete sysctl \
  'n/*/`sysctl -Na`/'

complete tmux \
  'n/*/(attach detach has kill-server kill-session lsc lscm ls lockc locks new refresh rename showmsgs source start suspendc switchc)/'

set _task_date="modified.after:2016-01-01"
complete task \
  'c/pri:/(L M H)/' \
  'c/project:/`task ${_task_date} _unique project`/' \
  'n/[0-9]*/(annotate edit modify done)/' \
  'p/2-/(project pri due)/:/' \
  'p/1/`echo add list ; task _unique id`/'

complete unrar \

complete unzip \

complete which \

complete zathura \

alias _comp_pkgs 'pkg info -q'
alias _comp_pkg_info '_comp_pkgs | xargs echo --list-files --pkg-message --comment --dependencies --required-by --size'
alias _comp_pkg_install 'sqlite3 /var/db/pkg/repo-FreeBSD.sqlite "select name from packages;"'

complete pkg \
  'p/1/(annotate autoremove delete info install iv rquery ri rv rw query search uv ur which)/' \
  'n/info/`_comp_pkg_info`/' \
  'N/info/`_comp_pkgs`/' \
  'n/delete/`_comp_pkgs`/' \
  'n/install/`_comp_pkg_install`/' \
  'n/rv/`pkg rquery "%n" | uniq`/' \
  'n/ri/`pkg rquery "%n" | uniq`/' \
  'n/rw/`pkg rquery "%n" | uniq`/' \

set _svn_commands=( add blame cat checkout cleanup commit copy delete diff export help import info \
  list ls lock log merge mkdir move propdel propedit propget proplist propset \
  resolved revert status switch unlock update )
set _svnsync_commands=( init sync copy-revprops info help )
set _svnsync_list=( \
  file:///home/storage/svn/server-dotfiles \
  file:///home/storage/svn/uzsolt.hu/ \
  svn+ssh://svn@svn.uzsolt.hu/usr/local/subversion/dokumentumok \
  svn+ssh://svn@svn.uzsolt.hu/usr/local/subversion/homefiles \
  svn+ssh://svn@svn.uzsolt.hu/usr/local/subversion/svnadmin \
  svn+ssh://svn@svn.uzsolt.hu/usr/local/subversion/texmf_own \
set _svn_props=( svn:global-ignores svn:ignore svn:log )
alias _comp_svn_modified 'svn status | sed -n "/^[AM]/ s,^[AM] *,,p"'
alias _comp_svn_new 'svn status | sed -n "/^?/ s,^? *,,p"'

complete svn \
  'p@1@$_svn_commands@' \
  'c@file://@d@' \
  'n@checkout@(file:// svn+ssh:// svn://)@@' \
  'n@help@$_svn_commands@' \
  'n@ls@(file:// svn+ssh:// svn:// ^/)@@' \
  'n@add@`_comp_svn_new`@' \
  'n@commit@`_comp_svn_modified`@' \
  'n@diff@`_comp_svn_modified`@' \
  'n@propedit@$_svn_props@' \
  'n@propget@$_svn_props@' \
  'n@propset@$_svn_props@' \
  'N@propedit@d@' \
  'n@revert@`svn status | sed -n "/^[ADM]/ s,^[ADM] *,,p"`@' \
  'n@status@`svn status | sed -n "/^[ADM?]/ s,^[ADM?] *,,p"`@'

complete svnadmin \
  'p@1@(crashtest create deltify dump freeze help  hotcopy list-dblogs list-unused-dblogs load lock lslocks lstxns pack recover \
    rmlocks rmtxns setlog setrevprop setuuid unlock upgrade verify)@' \
  'n@create@d@' \

complete svnsync \
  'p@1@$_svnsync_commands@' \
  'n@help@$_svnsync_commands@' \

set     red="%{\033[1;31m%}"
set   green="%{\033[0;32m%}"
set  yellow="%{\033[1;33m%}"
set    blue="%{\033[1;34m%}"
set magenta="%{\033[1;35m%}"
set    cyan="%{\033[1;36m%}"
set   white="%{\033[0;37m%}"
set     end="%{\033[0m%}"

set HOSTCOLOR="${green}"
set promptchars='$#'
set prompt = "\n${HOSTCOLOR}%M ${white}|${cyan} %T ${white}| ${cyan}%~${end} \n"
set prompt="${prompt}$ ${end}"

alias use-sb 'setenv SANDBOX `mktemp -d /home/zsolt/sandbox/sandbox.XXXXXXXX` ; tcsh -l ; rm -rf ${SANDBOX} ; unsetenv SANDBOX'

setenv XDG_CONFIG_HOME /home/zsolt/.config/
setenv XDG_CACHE_HOME /home/zsolt/.cache/

alias wcd "/usr/local/bin/wcd \!* ; source ${WCDHOME}/bin/wcd.go"

if ($tty == "ttyv0") then
  echo Starting Xorg...
  startx #&> /home/users/zsolt/logfiles/startx.log
  echo "Halt (h) Reboot (r) Nothing (n) ?"
  set answer = $<
  if ($answer == "h") then
    /sbin/shutdown -p now
  else if ($answer == "r") then
    /sbin/shutdown -r now
  if (${?SANDBOX} == 1) then
    set prompt = "${green}%n ${white}|${cyan} %T ${white}| ${yellow}%~${end} \n${magenta}<sandbox>${blue} $ ${end} "
    cd ${SANDBOX}
  else if (${?BURN} == 1) then
    cd ${BURN}
    set prompt = "${green}%n ${white}|${cyan} %T ${white}| ${yellow}%~${end} \n${magenta}<burn>${blue} $ ${end} "
    alias precmd du-tmp-burn
    # /usr/games/fortune freebsd-tips | cowsay -n
    if (${?TMUX_PANE} == 1) then
      if (${TMUX_PANE} == "%0") then
        set updatingdate = `date -v-1w +%Y%m%d`
        set tmpfile = `mktemp -t pkgupdating`
        if (`pkg updating -d ${updatingdate} | tee ${tmpfile} | wc -l` > 0) then
          cat ${tmpfile} | cowthink -n -f default | histring -E "^ [-_]*|.*AFFECTS.*|^\( [0-9]{8}:.*" -c green #| cowthink -n
        rm ${tmpfile}
    task list due.before:20d
    task list due.after:20d

set printexitvalue



Thanks: 4
Messages: 22

complete jexec  'p@1@`jls -N | awk \{\ print\ \$1\ \} | grep -v JID`@'
# jexec
backtunnels mariadb55   murmur      nginx       php54       proxies
devel       messengers  myservices  php52       php71