Share your .tcshrc file

I decieded to start this thread after reading the thread 'Which shell do you use?'.

I'll start, mine is below.

Code:
# .cshrc - csh resource script, read at beginning of execution by each shell
#
#

# -- Set up command aliases
alias searchports	'find /usr/ports -type f -name pkg-descr | xargs grep -i $1'
alias cdp	'echo $cdpath | tr -s : \\012'
alias checksym	'find -L . -type l'
alias cls	'clear'
alias cp	'cp -ip'
alias cx	'chmod ugo+x'
alias d		'tcsh $HOME/.login'
alias df	'df -h -t ufs,nfs'
alias exd	'export DISPLAY=":0"'
alias free	'freebsd-memory | tail -n5'
alias ft	'find . -maxdepth 1 -type f -mtime -1'
alias fta	'find . -type f -mtime -1'
alias grep	'grep --color="auto"'
alias h		'history'
alias h25	'history 25'
alias hist	'history|grep $1'
alias hs	'history | egrep'
alias j		'jobs -l'
alias key	'man -k'
alias la	'ls -a'
alias lf	'ls -FA'
alias ll	'ls -lA'
alias ls	'ls -LFGP'
alias lsa	'ls -ld .*'
alias lsc	'ls -sSh'
#alias lsd	'ls -ld *(-/DN)'
alias lsd	'ls -ld *'
alias lsnew	'ls -rtl *(.) | tail '
alias lt	'ls -t | head'
alias mc	'mc -ab'
alias mv	'mv -i'
alias na	'screen -t "\!:1" "\!:1"'
alias notes	'vim /home/rbelk/notes.txt'
alias ns	'screen -t "\!:1" ssh -o ServerAliveInterval=300 -o TCPKeepAlive=yes "\!:1"'
alias pi	'pkg_info'
alias pine	'alpine'
alias po	'popd'
alias pu	'pushd'
alias pwfh	'ps wfh'
alias g		'elinks http://www.google.com'
alias renew	'source ~/.tcshrc'
alias rlog	'rlog -zLT'
alias rm	'/usr/local/scripts/rm_alias.sh'
alias root	'sudo -i'
alias rr	'rehash ; renew'
alias rrm	'/bin/rm'
alias scppub	'scp $HOME/.ssh/id_dsa.pub "\!:1":~/.ssh/authorized_keys'
alias showpath	'echo $PATH | tr -s : \\012'
alias shred	'gshred'
alias sl	'screen -ls'
alias spin	'spinner -n'
alias spn	'portless -W'
alias srd	'screen -RD $USER'
alias t		'/usr/local/bin/todo -d $HOME/.todo.cfg'
alias tcfg	'vim ~/.tcshrc'
alias toupgrade	'pkg_version -o -I -L='
alias ttar	'tar -tvzf'
alias utar	'tar -xvzf'
alias vdiff	'vim -d'
alias vi	'vim'
alias viewlog	'screen -t viewlog sudo tail -F /var/log/all.log'
alias vnstat	'vnstat -i em0'
alias vvi	'/usr/bin/vi'
alias weather	'weather -a -z ms/USMS0175 -f'
alias webshare	'python -m SimpleHTTPServer 9914'
alias whatsmyip	'elinks -dump http://whatismyip.org/'
alias which-command	'whence'
alias xs	'screen -l -xR -S $USER'
alias yesterday	'date -v-1d +%d/%m/%Y'

[ -x /usr/local/bin/most ] && alias less	'most -w'
[ -x /usr/local/bin/most ] && alias more	'most -w'
[ -x /usr/local/bin/most ] && alias most	'most -w'

# -- A righteous umask
umask 22

# -- Set up search path
set path = (\
        /sbin \
        /bin \
        /usr/sbin \
        /usr/bin \
        /usr/games \
        /usr/local/sbin \
        /usr/local/bin \
        /usr/X11R6/bin \
        $HOME/bin \
        $HOME/mybin \
        /usr/local/scripts \
        /usr/local/uxscripts \
        )

# -- Set up CDPATH
set cdpath = (\
        . \
        ~/ \
        ~/folders \
        ~/projects \
        ~/work \
        )

# -- Set up global options
limit coredumpsize 0
setenv  LANG en_US.UTF-8
setenv  EDITOR  vim
setenv  PAGER   less
setenv  BLOCKSIZE       K
setenv  CLICOLOR
setenv  WWW_HOME "http://www.google.com/"
setenv	FTP_PASSIVE_MODE
setenv  LSCOLORS "ExGxFxdxCxegedabagExEx"
setenv  OS `uname`
setenv  GREP_COLOR '1;37;41'
setenv	HTTP_AUTH "'basic:*"

# -- An interactive shell -- set some stuff up
if ($?prompt) then
	set prompt="[%B%m: %/%b] `date +%a` %t <\!> $ "
	set colorcat
	set ignoreeof
	set autoexpand
	set autocorrect
	set correct=cmd
	set rmstar
	set filec
	set history = 1000
	set savehist = 1000
	set mail = (/var/mail/$USER)
	set noclobber
	set autolist
	set correct = cmd
	set nobeep
#	set watch = (0 any any)

	complete {,un}alias     'p/1/a/' 'p/2/c/'
	complete {c,push,pop}d  'C/*/d/'
	complete exec           'p/1/c/'
	complete man            'C/*/c/'
	complete {where,which}  'C/*/c/'
	complete {,un}set       'p/1/s/'
	complete {,un}setenv    'C/*/e/'
	complete printenv       'C/*/e/'
	complete bindkey        'p/1/b/'
	complete fg             'c/%/j/'
	complete kill           'c/%/j/' 'c/-/S/'
	complete chgrp          'p/1/g/'
	complete chown          'p/1/u/'
	complete limit          'C/*/l/'
	complete find           'p/1/d/' 'n/-user/u/' 'n/-group/g/'
	complete pkg_info	'c/-/(a b v p q Q c d D f g i I j k K r R m L s o G W O x X e E l t V P)/' \
			'n@*@`\ls -1 /var/db/pkg | sed "s%/var/db/pkg/%%;s%^\(.*\)-[0-9].*%\1%"`@'
	complete pkg_delete	'n@*@`\ls -1 /var/db/pkg | sed "s%/var/db/pkg/%%"`@'
	complete portmaster	'n@*@`\ls -1 /var/db/pkg | sed "s%/var/db/pkg/%%;s%^\(.*\)-[0-9].*%\1%"`@'
	complete portsnap	'c/-/(I d f k p s)/' \
			'n/-d/d/' \
			'n/-p/d/' \
			'n/*/(fetch extract update)/'
	complete pkg_add 'n@-r@`awk -F\| \{sub\(/-\[0-9\]\.\*\/\,\"\"\,\$1\)\;print\ \$1\} /usr/ports/INDEX | sort -u`@'
endif

Please share yours. Moderators, if you think this is in the wrong forum please move.
 
Mine's fairly standard:
Code:
alias h         history 25
alias j         jobs -l
alias la        ls -a
alias lf        ls -FA
alias ll        ls -lA

if ( -x /usr/local/bin/vim ) then
        alias vi        vim
endif

# A righteous umask
umask 22

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

setenv  EDITOR  vi
setenv  PAGER   less
setenv  BLOCKSIZE       K
setenv  LC_ALL en_US.ISO8859-1

setenv  CLICOLOR

switch($TERM)
        case "xterm*":
                setenv TITLE "%{\033]0;%n@%m:%~\007%}"
                breaksw
        default:
                setenv TITLE ""
                breaksw
endsw

if ($?prompt) then
        # An interactive shell -- set some stuff up
        set filec
        set history = 100
        set savehist = 100
        set mail = (/var/mail/$USER)
        if ( $?tcsh ) then
                bindkey "^W" backward-delete-word
                bindkey -k up history-search-backward
                bindkey -k down history-search-forward
                set prompt = "${TITLE}%n@%m:%~%#"
        endif
endif
 
Nothing big except for all the completion settings I just shamelessly copied from rbelk.

A few shortcuts for tracking down spam senders.
Code:
alias afri      whois -h whois.afrinic.net
alias arin      whois -h whois.arin.net
alias apnic     whois -h whois.apnic.net
alias ripe      whois -h whois.ripe.net
alias lacnic    whois -h whois.lacnic.net
alias jpnic     'whois -h whois.nic.ad.jp \!*/e'

Also this, so the console autorepeat isn't slower than a turtle in molasses.
Code:
switch ($tty)
  case "ttyv*":
    alias precmd /usr/sbin/kbdcontrol -r fast
endsw

And of course Home and Delete:
Code:
bindkey "\e[3~" delete-char
bindkey "\e[1~" beginning-of-line
 
http://code.arp242.net/config/src/tip/home/dot.tcsh/?at=default

It should work on FreeBSD, OpenBSD, OpenSolaris, and Linux.
It should in general be fairly portable (e.g. It checks if "vim" actually exists before setting $EDITOR to vim, etc.).

It's a bit of a mess and has "grown" over the last few years. I also have a couple of different flavours on different machines floating around :-/


Edit 20141029: Update link
 
Last edited:
Work in progress

I'd like to join the thread and think I have a fair bit to contribute. I'm sure there's some fun toys in here that you might be interested in (especially the randomizations).

My ~/.tcshrc file:
Code:
# -*- tab-width:  4 -*- ;; Emacs
# vi: set tabstop=4     :: Vi/ViM
#
# .tcshrc
#   Author:      Devin Teske <dteske@vicor.com>
#   Last Change: 2011 Mar 2
############################################################ GLOBALS

#
# Global exit status variables
#
setenv SUCCESS 0
setenv FAILURE 1

#
# Are we running interactively?
#
setenv interactive 0
if ( $?prompt ) then
    setenv interactive 1
endif

############################################################ ALIASES

#
# Alias to set the title of your ANSI-compatible shell window.
#
alias settitle printf '"\033]2;\!*\a\033]1;\!*\a\033]0;\!*\a"'

#
# Random keepalive [ka] alias (based on system-availability of various
# fun utilities).
#
alias RANDOM 'printf "%u\n" 0x`xxd</dev/urandom|head -1|cut -b 10-13`'
alias have 'which \!^ >& /dev/null'
@ n = 0
have worms   && eval set ka$n='"worms -d 25"' && @ n++
have rain    && eval set ka$n='"rain -d 50"' && @ n++
have grdc    && eval set ka$n='"grdc"' && @ n++
have fortune
if ( $? == 0 ) then
    set fort='sh -c "while :;do fortune;sleep 80;echo --;done"'
    eval set ka$n="'$fort'"
    @ n++
endif
if ( $n <= 0 ) then
    set ka0="sh -c 'while :;do echo -n .;sleep 80;done'"
    @ n++
endif
alias ka '@ x = `RANDOM` / ( 65537 / '$n' ); eval eval \$ka$x'
unset n

#
# Alias to use in-place of grep(1) whenever you want to preserve the first line
# of output (often the header when viewing output from ps(1), lsof(8), df(1),
# netstat(8), arp(8), lsmod(8), route(8), free(1), and many many others).
#
alias hgrep awk '"BEGIN { getline; print } /\!^/ { print }"' \!:2\*

#
# Alias for becoming root while maintaining shell customizations.
#
alias srsu sr env tcsh

############################################################ SHELL BEHAVIOR

#
# Set prompt style
#
set prompt='%{\033[32;1m%}%n@%m %{\033[34;1m%}%c %#%{\033[0m%} '

#
# Set the window title for terminals such as "xterm", "rxvt", and others
#
if ( $interactive ) then
    settitle $USER@$HOST $HOME
endif

#
# Make new files group-writable by default
#
umask 002

############################################################ MISCELLANEOUS

#
# cvs(1) settings
#
setenv CVS_RSH cvs_rsh
setenv CVSROOT cvs:/repos/projects

#
# *beep**beep**beep**beep**beep*X(1) settings
#
setenv IRCNICK devinteske
setenv IRCSERVER frenode.net
setenv IRCNAME dteske

#
# sysrc(8) settings
#
setenv SYSRC_VERBOSE 1

#
# Override the default password prompt for sudo(8). This helps differentiate
# the sudo(8) password prompt from others such as su(1), ssh(1), and login(1).
#
setenv SUDO_PROMPT '[sudo] Password:'

NOTE: My .bash_profile is over 6-times larger (note: I may be a bash user, but I certainly do not hate on [t]csh).
 
Just wanted to add some autocompletions that have been useful to me:

service(8) autocompletes from system and installed port services.
Code:
complete service        'n@*@`ls /etc/rc.d /usr/local/etc/rc.d | sed -e "/:/d"`@'

pkill(1) autocompletes from the list of running processes.
Code:
complete pkill          'n@*@`ps -a -x -c -o command="" | sort | uniq`@'

Revised autocomplete definitions for ports and packages.
Code:
complete pkg_delete     'c/-/(i v D n p d f G x X r)/' \
                        'n@*@`ls /var/db/pkg`@'
complete portmaster     'c/-/(C G H K B b g n t v w f i D d m x P PP)/' \
                        'n@*@`ls /var/db/pkg`@'
complete portupgrade    'c/-/(A b B c C D e f F i k l L m M n N o O p P PP q r R s S u v w W x y)/' \
                        'n@*@`ls /var/db/pkg`@'
 
That reminds me, I need to look at that too. I'd like to auto-complete zfs filesystems.
 
Some "funnies" in this one

Kind of interesting how your .cshrc shows some history about you after several years.

Nothing really "uber-leet" here; I find the DOS substitutions kinda funny in retrospect, though :e

Code:
# $FreeBSD: src/share/skel/dot.cshrc,v 1.13 2001/01/10 17:35:28 archie Exp $
#
# .cshrc - csh resource script, read at beginning of execution by each shell
#
# see also csh(1), environ(7).
#
alias h		history 25
alias j		jobs -l
alias ls	ls -FG
alias la	ls -a
alias lf	ls -FA
alias ll	ls -lAFG
alias mail      mutt
alias nomail    "kill -HUP `pgrep thunderbird`"
alias lockp	"cls && lock -p -t 15000"
alias rootmail	"sudo mutt -f /var/mail/root"
alias pt	"pgrep thunderbird"
alias tb	"thunderbird &"
alias pico      nano
alias snoop	"sudo tcpdump -i xl0 | grep -v ssh | grep -v myserver"
alias py	"ping -t 6 yahoo.com"
alias dir       ls
alias rm        rm -i
alias mv	mv -i
alias cp	cp -i
alias me	whoami
alias a:	"sudo mount_msdosfs /dev/fd0 /floppy && cd /floppy && ls -l"
alias noa:	"cd && sudo umount /floppy"
alias tm	/usr/local/textmaker5/textmaker/tm
alias mp	mousepad
alias up	ping -t2 yahoo.com
alias dial	sudo ppp -nat -background tdon
alias undial    "pgrep ppp | xargs sudo kill"
alias cls	clear
alias clss	"clear && ls"
alias d:	sudo mount_cd9660 /dev/acd0 /cdrom
alias checkflow sudo tcpdump -i tun0
alias localflow sudo tcpdump -i vr0
#alias cat	/usr/local/bin/php -q /home/kadmin/scripts/cat
alias refetch   /usr/local/bin/sudo /usr/local/bin/php -q /home/kadmin/scripts/refetch
alias amavisd   sudo su vscan -c /usr/local/sbin/amavisd
alias mm	"cd && cls"
alias fdformat  sudo /usr/sbin/fdformat -f 1440 /dev/fd0
alias squidk	"pgrep squid | xargs sudo kill -HUP"
alias spell	/home/kadmin/scripts/spell
alias netoff    "sudo ipfw add 00001 deny ip from any to any via xl0"
alias neton     "sudo ipfw delete 00001"
alias zeke     "Eterm -T Yolanda -e ssh yolanda &" 
alias lisha     "Eterm -T Kermit -e ssh kermit &"
alias killmonkey "/bin/pgrep seamonkey | /usr/bin/xargs /bin/kill -s QUIT"
alias deadmonkey "/bin/pgrep seamonkey | /usr/bin/xargs /bin/kill -s QUIT"
alias dors "sudo /home/kadmin/scripts/unban runescape; sudo ipfw add 653 allow ip from foobar to any"
alias nors "sudo reban runescape; sudo ipfw delete 653"
alias unbanned "/usr/bin/grep # /etc/banned.list"
alias moz "cd /usr/local/lib/mozilla-gtk2/ && sh run-mozilla.sh &"
alias mailconnect "sudo ssh -L localhost:24:yolanda:52525 yolanda"
alias spammv "scp ~/spammers kadmin@yolanda:/home/kadmin/"

set path = (/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin /usr/X11R6/bin $HOME/bin $HOME/scripts /usr/local/libexec/nut)

#set watch = (0 any any)

setenv  CVS_RSH ssh
setenv	EDITOR	nano
setenv	PAGER	more
setenv	BLOCKSIZE	M
setenv  EMAIL  "me@mydomain.com"
setenv  CLICOLOR
setenv	TERM xterm-color
limit coredumpsize 0
set correct=cmd
#set prompt = "\n<%B$user%b@%B%m%b> [%/] [%B%T%b] \n% "

if ($?prompt) then
	# An interactive shell -- set some stuff up
	set prompt="\n%B%{\033[34m%}[%h] %d %D.%w.%Y %P\n%{\033[31m%}[%n@%m][%~]\n%{\033[30m%}%b"
	set filec
	set history = 5
	set savehist = 5
	set mail = (/var/mail/$USER)
	if ( $?tcsh ) then
		bindkey "^W" backward-delete-word
		bindkey -k up history-search-backward
		bindkey -k down history-search-forward
	endif
endif

cd ~
alias service network restart     echo 'Are you sure, or did you mean /etc/rc.d/netif restart?' 
alias 'service network restart'     echo 'Are you sure, or did you mean /etc/rc.d/netif restart?' 
alias freecell "wine /usr/home/kadmin/.wine/drive_c/windows/system32/freecell.exe"
 
A better pkill(1) completion:
Code:
complete pkill          'c/-/(1 2 3 6 9 14 15 HUP INT QUIT ABRT KILL ALRM TERM)/'\
                        'n@*@`ps -a -x -c -o command="" | sort | uniq`@'

Incidentally, the tcsh(1) section on completion is totally undecipherable to me. The above is because of some hints from this. Still not sure what n@*@ does, but if understanding was required before use, I wouldn't be here.
 
service(8) autocompletes from system and installed port services.
Code:
complete service        'n@*@`ls /etc/rc.d /usr/local/etc/rc.d | sed -e "/:/d"`@'

I use this for completing service(8):
Code:
complete service 'n/*/`service -l`/'

Seems a bit simpler to me :)

I also have this for adding signals, it seems more complete than your version, doesn't add process names or PID's though:
Code:
complete kill 'c/-/S/' 'p/1/(-)//'
complete pkill 'c/-/S/' 'p/1/(-)//'

If you can figure out a way to get make(1) to show a list of all possible targets, that's one I want to do also.

Not a bad idea, I only tested this quickly. Seatbelt not included :)

The command to get a list of targets is:
Code:
make -pn | egrep '^[^#].*: $' | sed 's|: $||; s|\w||g'

Unfortunately, using this directly in a complete command is problematic ... AFAIK tcsh doesn't provide an easy way to escape the dollar sign ... :-/ tcsh has some stupid limitations.

I put it in ~/bin/compmake and used this in my ~/.cshrc
Code:
complete make 'n/*/`compmake`/'

Seem to work for at least ports and /usr/src ...

wblock@ said:
A better pkill(1) completion:
Code:
complete pkill          'c/-/(1 2 3 6 9 14 15 HUP INT QUIT ABRT KILL ALRM TERM)/'\
                        'n@*@`ps -a -x -c -o command="" | sort | uniq`@'

Incidentally, the tcsh(1) section on completion is totally undecipherable to me. The above is because of some hints from this. Still not sure what n@*@ does, but if understanding was required before use, I wouldn't be here.

The @'s are just a different delimiter, just as you can use a whole bunch of delimiters with most regexp implementations.
It's confusing to use an @ here because this is also a built-in and because it's far from a "conventional" delimiter like slash, comma, or pipe.
I'm not sure if all character are allowed like in regexps, IIRC @ is the only one mentioned explicitly in the manual

As a certain wizard would say, "one does not simply read tcsh(1)"
(t)csh is one of the more archaic pieces of "old" UNIX/BSD legacy. I use it because I've been using it so long I can do most of the stuff blind folded, but the more I learn about it, the more it's obvious it's really not very good (See: dollar-sign escape nonsense above). If you're new, I really wouldn't recommend it...
 
Here's a (better?) version which also skips all targets starting with a dot, typically not something you'd want to run as a user.

Code:
make -pn | egrep '^[^#.].*: $' | sed 's|: $||; s|\w||g'
 
wblock@ said:
Code:
complete make           'n@*@`make -pn | sed -n -E "/^[#_.\/[:blank:]]+/d; /=/d; s/[[:blank:]]*:.*//gp;"`@'
And now my brain hurts.

That has to be the best CSH alias I've seen in this thread, thanks wblock. I'll have to study this tomorrow. I'd stay up all night trying to figure the alias out! I started this thread to learn more about CSH and it's differences from the bourne shell and I've learned a lot!
 
It's awesome, wblock.

I haven't made much changes to .cshrc.
prompt:
Code:
set promptchars='$#'
set prompt="%{^[[01;34;1m%}[%T] %n@%m [%~] %#%{^[[00;39m%} "
It's looking like that (i have dark background): [14] user@host [~/tmp] $

and some keybindings:
Code:
                bindkey "^W" backward-delete-word
                bindkey -k up history-search-backward
                bindkey -k down history-search-forward
                bindkey "\e[1~" beginning-of-line  # Home
                bindkey "\e[3~" delete-char        # Delete
                bindkey "\e[4~" end-of-line        # End
 
wblock@ said:
A better pkill(1) completion:
Code:
complete pkill          'c/-/(1 2 3 6 9 14 15 HUP INT QUIT ABRT KILL ALRM TERM)/'\
                        'n@*@`ps -a -x -c -o command="" | sort | uniq`@'

tcsh(1) can complete signals too. So, a simpler form could look like this:

Code:
complete pkill          'c/-/S/'\
                        'n@*@`ps -a -x -c -o command="" | sort | uniq`@'
 
Interesting. It's possible to do multiple completions for the same parameter:
Code:
complete pkill 'c/-[A-Z]/S/' 'c/-[0-9]/(1 2 3 6 9 14 15)/' 'n@*@`ps -axc -o command="" | sort | uniq`@'

[A-Z] and [0-9] are glob patterns, not regexes.

I suspect @ is used just to avoid conflict with other common delimiters.
 
Currently something like this:
Code:
# Path
set path = (/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin /usr/X11R6/bin $HOME/bin)

if ($uid == 0) then
	set user = root
endif

set prompt = "%n@%m [%~] "

# Environment
setenv PAGER more
setenv LC_CTYPE sv_SE.UTF-8

# Enable colorized output
set color

# BSD ls colors
setenv LSCOLORS "Dxfxcxdxbxegedabagacad"

# Linux ls colors (but tcsh also wants it for autocompletion colors)
setenv LS_COLORS "di=01;33:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43:"

# Automatic filename completion
set filec

# List autocomplete possibilies
set autolist

# No beeping
set nobeep

# History
set history = 1000
set savehist = 1000

# Better ls
alias ls ls -ahoGF

# Set vim as default editor if it exists
if ( -x /usr/local/bin/vim ) then
	# FreeBSD default vim location
	setenv EDITOR /usr/local/bin/vim
	alias vi vim
else if ( -x /usr/bin/vim ) then
	# Mac OS X default vim location
	setenv EDITOR /usr/bin/vim
	alias vi vim
endif

# Manual pages with color
setenv LESS_TERMCAP_mb `echotc md; echotc AF 1`
setenv LESS_TERMCAP_md `echotc md; echotc AF 1`
setenv LESS_TERMCAP_me `echotc me`
setenv LESS_TERMCAP_se `echotc me`
setenv LESS_TERMCAP_so `echotc md; echotc AF 3; echotc AB 4`
setenv LESS_TERMCAP_ue `echotc me`
setenv LESS_TERMCAP_us `echotc md; echotc AF 4`
Latest version is always available from https://github.com/joeldahl/dotfiles/blob/master/.tcshrc
 
Code:
if ( -x /usr/local/bin/vim ) then
	# FreeBSD default vim location
	setenv EDITOR /usr/local/bin/vim
	alias vi vim
else if ( -x /usr/bin/vim ) then
	# Mac OS X default vim location
	setenv EDITOR /usr/bin/vim
	alias vi vim
endif

You can use -X (Capital X)

Code:
           X   Executable in the path or shell builtin, e.g., `-X ls' and  `-X
               ls-F' are generally true, but `-X /bin/ls' is not (+)

i.e.
Code:
if (-X vim) then
	setenv EDITOR vim
	alias vi "vim"
else if (-X vi) then
	setenv EDITOR vi
endif
 
wblock@ said:
Just wanted to add some autocompletions that have been useful to me:


Revised autocomplete definitions for ports and packages.
Code:
complete portupgrade    'c/-/(A b B c C D e f F i k l L m M n N o O p P PP q r R s S u v w W x y)/' \
                        'n@*@`ls /var/db/pkg`@'


Hi.

Thanks for the inspiration for the portupgrade autocompletion!

Here is my version that, when autocompleting, only shows old ports for which a newer port version is available. (you need an up to date INDEX file in your portstree for this to work)

Code:
complete portupgrade    'c/-/(A b B c C D e f F i k l L m M n N o O p P PP q r R s S u v w W x y)/' \
                        'n@*@`/usr/sbin/pkg_version -vq --index-only -L= | cut -d " " -f1`@'
 
Here is few lines from my ~/.tcshrc

My custom prompt
set prompt = " %{\033[1;37m%}%T %{\033[1;32m%}%C%{\033[1;37m%} %#%{\033[0m%} "
e4tsV8B.png


same, but without bold fonts:
set prompt = " %T %{\033[0;32m%}%C%{\033[0m%} %# "

All prompt colors:
ol0lOM2.png

Code:
%{\033[0;31m%} — red
%{\033[1;31m%} — bold red
%{\033[0;32m%} — green
%{\033[1;32m%} — bold green
%{\033[0;33m%} — yellow
%{\033[1;33m%} — bold yello…
etc.
Color codes with 40 — %{\033[0;4*m%} should change font background, for example:
wXVoTV0.png


Note:
You always need to put the %{\033[0m%} at the end of your prompt, to reset colors to default.

For underlined text, use "%{\033[4;3*m%}", for example
set prompt = "[%P] %{\033[1;32m%}%n%{\033[1;37m%}@%m [B]%{\033[4;34m%}[/B]%/%{\033[0m%} (%l) \n%# "

Some tcsh codes:
`man tcsh` said:
%/ The current working directory
%~ The current working directory, but with one's home directory represented by `~'
%c The trailing component of the current working directory
%C Like %c, but without `~' substitution
%M The full hostname
%m The hostname up to the first `.'
%t The time of day in 12-hour AM/PM format
%T Like `%t', but in 24-hour format
%p The `precise' time of day in 12-hour AM/PM format, with seconds
%P Like `%p', but in 24-hour format (but see the ampm shell variable)
%n The user name
%N The effective user name
%d The weekday in `Day' format
%D The day in `dd' format
%w The month in `Mon' format
%W The month in `mm' format
%y The year in `yy' format
%Y The year in `yyyy' format
%l The shell's tty
%L Clears from the end of the prompt to end of the display or the end of the line


Nice alias for ports usage
Code:
alias p       'cd /usr/ports && cd'
Uai6z4S.png


Some more "alias"-es:
Code:
alias c         'cat'
alias q         'exit'
alias h         'history 25'
alias f         'psearch'
alias F         'find . -type f'
alias grep      'grep --color'
alias gnugrep   '/usr/local/bin/grep --color'
alias g         'grep -i'
alias v         'vim'
alias .         'pwd'
alias ...       '../..'
alias ls        'ls -SF'
alias la        'ls -a'
alias ll        '\ls -Flht'
alias mkdir     'mkdir -p'
alias s         'sudo'
alias ss        'sudo su -'
alias S         'source ~/.tcshrc'
alias H         'vim ~/.csh_history'
alias stat      'stat -x'
alias date      'date +"%d-%m-%Y, %H:%M"'
alias tkill     'tmux kill-session -t'
alias aw        'ansiweather'
alias cputemp   'sysctl -a | grep "dev.cpu.*.temperature"'
(also try shells/tcshrc)


Also tcsh got built in autocorrect function, add "set correct = cmd" to ~/.tcshrc for example.
Some other features that I use:
Code:
if ($?prompt) then
        set prompt = " %T %{\033[0;32m%}%C%{\033[0m%} %# "
        set promptchars = "%#"
        set history = 5000
        set savehist = (5000 merge)
        set histfile = "$HOME/.csh_history"
        set histdup = erase              # save only unique history events
        set notify                       # notification when jobs change state
        #set recexact                    # completion always completes on a first exact match
        set autocorrect                  # spell-word editor command is invoked automatically
        set autoexpand                   # run expand-history before each completion attempt
        set implicitcd                   # change directory without cd
        set correct = cmd                # commands are automatically spelling-corrected
        set symlinks = chase             # symbolic link is expanded to the real name of the directory
        set complete = enhance           # completion ignores case and considers hyphens and underscores
        set autolist = ambiguous         # choices are listed only when completion fails
        set matchbeep = ambiguous        # beeps only when there is no match
        set color = ls-F                 # enables colors for the builtin autolist (TAB)
        set padhour                      # enable the printing of padding '0' for hours
        set noding                       # disable "Ding!" in the prompt time
        set rmstar                       # user is prompted before `rm *' is executed
        if ( $?tcsh ) then
                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
        endif
endif

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


If you do not want to type manually "rehash" after each package installation,
add
Code:
set autorehash = always
to .tcshrc, and the list of available commands will be rebuilt for
each command completion or spelling correction attempt.

To auto start sysutils/tmux terminal multiplexer with /bin/tcsh shell, I'm using
Code:
 if (! $?TMUX) tmux -l -2
in ~/.tcshrc.



And "just for lulz",
alias for thefuck (app which corrects previous console command).
Code:
alias fuck   'set fucked_cmd=`history -h 2 | head -n 1` && eval `thefuck ${fucked_cmd}`'
alias F       'fuck'
To install thefuck, install devel/py-pip, devel/py-colorama, devel/py-decorator, devel/py-pathlib2 and sysutils/py-psutil, then execute
% pip install --user thefuck
qFnooDq.png
 
Last edited by a moderator:
Code:
# Change only root's prompt
if (`id -g` == 0) then
   set prompt="root@%m# "
endif

# This maps the "Delete" key to do the right thing
# Pressing CTRL-v followed by the key of interest will print the shell's
# mapping for the key
bindkey "^[[3~" delete-char-or-list-or-eof

# Make the Ins key work
bindkey "\e[2~" overwrite-mode

# Some common completions
complete cd       'p/1/d/'
complete chown          'p/1/u/'
complete dd       'c/[io]f=/f/ n/*/"(if of ibs obs bs skip seek count)"/='
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)/' \
             'n/*/d/'
complete fg       'c/%/j/'
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/' \
             'n/*/f/'
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 make       'p@1@`make -pn | sed -n -E "/^[#_.\/[:blank:]]+/d; /=/d; s/[[:blank:]]*:.*//gp;"`@' \
                 'n@-V@`make -ndv | & grep Global: | sed -E -e "s/^Global://" -e "s/ .*//" -e "/^[[:lower:]]/d" | sort | uniq`@'
complete man       'C/*/c/'
complete netstat   'n@-I@`ifconfig -l`@'
complete pkg_delete     'c/-/(i v D n p d f G x X r)/' 'n@*@`ls /var/db/pkg`@'
complete pkg_info       'c/-/(a b v p q Q c d D f g i I j k K r R m L s o G O x X e E l t V P)/' 'n@*@`\ls -1 /var/db/pkg | sed s%/var/db/pkg/%%`@'
complete ping       'p/1/$hosts/'
complete pkill       'c/-/S/' \
                 'n@*@`ps -axc -o command="" | sort | uniq`@'
complete portmaster   'c/--/(always-fetch check-depends check-port-dbdir clean-distfiles clean-packages delete-build-only \
               delete-packages force-config help index index-first index-only list-origins local-packagedir \
               no-confirm no-index-fetch no-term-title packages packages-build packages-if-newer packages-local \
               packages-only show-work update-if-newer version)/' \
             'c/-/(a b B C d D e f F g G h H i l L m n o p r R s t u v w x)/' \
             'n@*@`pkg_info -E \*`@'
complete rsync   "c,*:/,F:/," \
             "c,*:,F:$HOME," \
             'c/*@/$hosts/:/'
complete scp   "c,*:/,F:/," \
             "c,*:,F:$HOME," \
             'c/*@/$hosts/:/'
complete service      'c/-/(e l r v)/' 'p/1/`service -l`/' 'n/*/(start stop reload restart status rcvar onestart onestop)/'
complete svn       'C@file:///@`'"${HOME}/etc/tcsh/complete.d/svn"'`@@' \
             'n@ls@(file:/// svn+ssh:// svn://)@@' \
             'n@help@(add blame cat checkout cleanup commit copy delete export help import info list ls lock log merge mkdir move propdel \
               propedit propget proplist propset resolved revert status switch unlock update)@' 'p@1@(add blame cat checkout cleanup commit \
               copy delete export help import info list ls lock log merge mkdir move propdel propedit propget proplist propset resolved \
               revert status switch unlock update)@'
complete ssh   'p/1/$hosts/' \
             'c/-/(l n)/' \
             'n/-l/u/ N/-l/c/ n/-/c/ p/2/c/ p/*/f/'
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)/'
complete which   'C/*/c/'

if ( -f /etc/printcap ) then
  set printers=(`sed -n -e "/^[^    #].*:/s/:.*//p" /etc/printcap`)
  complete lpr   'c/-P/$printers/'
  complete lpq   'c/-P/$printers/'
  complete lprm   'c/-P/$printers/'
endif

set prompt="%{\e[2;37m[%P] %{\e[0;33m%}%n%{\e[0m%}@%{\e[34m%}%m %{\e[32m%}%~%{\e[31m%} "\$"%{\e[0m%} "

# Color ls
alias ll   ls -l
alias ls   ls -G
alias la   ls -a
alias ..   cd ..
alias dload   youtube-dl -x --audio-format mp3 --audio-quality 320K

# Color on many system utilities
setenv CLICOLOR 1

# other autolist options
set       autolist = TAB

L4StGal.png
 
By the way… new tcsh version was released,
Code:
% tcsh --version
tcsh 6.20.00 (Astron) 2016-11-24 (x86_64-amd-FreeBSD) options wide,nls,dl,al,kan,sm,rh,color,filec
It is available now on FreeBSD 11.0-STABLE, on FreeBSD 12.0-CURRENT and on FreeBSD 10.3-STABLE.

FreeBSD 10.3-RELEASE and FreeBSD 11.0-RELEASE still uses
Code:
tcsh 6.18.01 (Astron) 2012-02-14 (i386-intel-FreeBSD) options wide,nls,dl,al,kan,sm,rh,color,filec
If you want to use tcsh 6.20.00 on FreeBSD 10.3-RELEASE or FreeBSD 11.0-RELEASE,
you can install it to /usr/local:
Code:
% wget ftp://ftp.astron.com/pub/tcsh/tcsh-6.20.00.tar.gz
% tar xvf tcsh-6.20.00.tar.gz
% cd tcsh-6.20.00/
% ./configure
% make
% sudo make install
% sudo mv /bin/tcsh /bin/tcsh.bak
% sudo ln -s /usr/local/bin/tcsh /bin/tcsh
Just switch to original /bin/tcsh when you'll do a freebsd-update. Also use /bin/csh like a root shell.

I really hope that thay fixed tcsh history, 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
OPIM99k.png


UPD: Solved. It seems
Code:
if ($?prompt3) then
    alias postcmd    'history -S'     # update and save history after each command
endif
do the job, without any issues. When shell is interactive, it'll save history after each command,
also history between different tcsh sessions will be shared, because it also updates current session history list.
It should be added to the bottom of ~/.tcshrc, because histfile should be set before.

Also I cannot find anything about tcsh builtin history command and about its flags
9ATLS2o.png

TC Shell power users, where can I read about it? man history is not helpful at all, because it opens this manual page,
also I cannot find anything about history flags (-chrSLMT) on tcsh manual page:
GNkkxZb.png

Or may be it is a bug and I should create a bug report?
 
Last edited by a moderator:
Back
Top