## Gentoo tcsh pre 6.14-r1 compatibility script
##
## Don't activate this script unless you want the behaviour as supplied
## by gentoo ebuilds prior to 6.14-r1.  If you wonder what it does, you
## probably don't want this at all, so stay away from it.
##

##
## Start by unsetting all our variables.  This is needed to prevent
## inheritance from the shell that started us -- e.g. when performing a
## 'su'.
##
unsetenv TCSH_SHELL_SAFEHISTORY
unsetenv TCSH_SHELL_AUTOLOGOUT
unsetenv TCSH_SHELL_SAFETY
unsetenv TCSH_SHELL_DOS
unsetenv TCSH_SHELL_CDALIAS
unsetenv TCSH_SHELL_COMPLETION
unsetenv TCSH_SPELL_COMPLETE

##
## Get our own settings.  Make sure they exist in the user's directory.
## Only copy newbee settings file if no .tcshrc is yet there.
## Note: the last thing differs from previous versions, but I guess it
## won't harm, earlier please people.
##
if ( ! -e ~/.tcsh.config ) then
	if ( ! -e ~/.tcshrc ) then
		if ( -e /etc/skel/.tcsh.config ) then
			echo ">>> Copying /etc/skel/.tcsh.config to your home directory ..."
			cp /etc/skel/.tcsh.config ~/.tcsh.config
			echo ">>> Please edit it to fine-tune the TCSH behaviour or remove"
			echo ">>> it and add a .tcshrc file"
		else
			echo "### Missing .tcsh.config!"
		endif
	endif
endif
if ( -e ~/.tcsh.config ) then
	source ~/.tcsh.config
endif

# Everything after this point is interactive shells only.
if ( $?prompt == 0 ) goto end

##
## Load our aliases -- for interactive shells only
## These are controlled by the .tcsh.config file
##
if ( -e /etc/profile.d/tcsh-aliases ) then
    source /etc/profile.d/tcsh-aliases
endif


##
## Load our command completions -- for interactive shells only
## Don't load them, as they are meant as an example
##
if ( $?TCSH_SHELL_COMPLETION ) then
    if ( -e /etc/profile.d/tcsh-complete ) then
        source /etc/profile.d/tcsh-complete
    endif
endif


##
## Load optional bindkeys
##
if ( $?TCSH_FKEYS ) then

# ESC-left-arrow : go to beginning of left word.        
# The second version is used to fix a strange bug where the binding
# stops working after some usage. Did not manage to recreate.
bindkey    ^[^[[D vi-word-back
bindkey	   OD vi-word-back

# ESC-right-arrow : go to beginning of right word.
# The second version is used to fix a strange bug where the binding
# stops working after some usage. Did not manage to recreate.
bindkey    ^[^[[C vi-word-fwd
bindkey	   OC vi-word-fwd

# F1 : help on command currently typed(if 'ls passwd', help on 'ls').
# first: while in console mode, second: while in X
bindkey    ^[[[A   run-help
bindkey    OP    run-help

# F2 : set the mark command to cursor position.
# first: while in console mode, second: while in X
bindkey  ^[[[B    set-mark-command 
bindkey  OQ     set-mark-command 

# F3 : move cursor to the marked position.
# first: while in console mode, second: while in X
bindkey   ^[[[C   exchange-point-and-mark 
bindkey   OR    exchange-point-and-mark 

# F4 : --empty--
# first: while in console mode, second: while in X
bindkey   ^[[[D   undefined-key
bindkey   OS   undefined-key

# F5 : check line for spelling and make changes.
# first: while in console mode, second: while in X
bindkey    ^[[[E   spell-line
bindkey    [15~   spell-line

# F6 : check current word for spelling and make changes.
# same in both console and X modes
bindkey    ^[[17~  spell-word

# F7 : insert last item of previous command.
bindkey    ^[[18~  insert-last-word

# F8 : search in history backwards for line beginning as current.
bindkey   ^[[19~  history-search-backward

# F9 : clear screen.
# You may be in the middle of a command when you use this.
# Does not affect what you are writing at the moment.
bindkey    ^[[20~  clear-screen

# F10 : do an 'ls -l'.    (\16 is Ctrl-U on Linux(and Sun?))
bindkey -s ^[[21~  "\16ls -l\n"

# F11 : display load average and current process status.
bindkey    ^[[23~  "/usr/bin/uptime ; ps"

# F12 : do a ala-csh completion.
bindkey    ^[[24~  complete-word-raw

#######################################
# Advanced settings

# Thanks to Carlos Duarte <cgd@teleweb.pt>
# Eazy edit of path, type Ctrl-X p
bindkey -s '^Xp'        '. `echo $path`^X*)^A^Dset path = ( '

# Ctrl-X *   Expand glob. example: ls *<^X*>  will expand the line
# default behaviour

# Ctrl-X $   Expand variables. example: $TERM<^X$> with give  vt100
# default behaviour

endif

##
## Various settings
##

# Switch to insert mode at the start of each line.
set inputmode=insert

# Do autolisting of commands while completing.
set autolist

# Do autocorrection while completing...
set autocorrect

# Use the history of commands to aid expansion.
# Found in new versions of tcsh (at least 6.10)
set autoexpand

# Enable enhanded completion: 1) ignores case and 2) considers
# periods, hyphens and underscores (`.', `-' and `_')  to  be
# word separators and hyphens and underscores to be equivalent.
if ( $?TCSH_IGNORE_CASE ) then
	set complete=enhance
else
	unset complete
endif

# Perform both completion and spelling correction of the command line.
if ( $?TCSH_SPELL_COMPLETE ) then
	set correct=all
else
	unset correct
endif

# Configure the auto-logout feature.
if ( $?TCSH_SHELL_AUTOLOGOUT ) then
    set autologout=$TCSH_SHELL_AUTOLOGOUT
else
    unset autologout
endif

# How to handle symbolic links.  Can be unset, or set to chase, ignore,
# or expand.
set symlinks=ignore

# After a 'Ctrl-Z', it lists all the jobs.
set listjobs=long

# Ask for confirmation when 'rm *'.
set rmstar

# Files that are to be ignored from completion.
set fignore=(.o \~ .bck)

# Ask before listing more than 20 rows of choices
set listmaxrows=20

# Show job completions when they're done
set notify

end:
