Configuration_Files/terminal/yashrc
2021-06-30 00:50:24 -03:00

269 lines
6.8 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# enable bash-like extended expansion
set --brace-expand
# enable recursive pathname expansion
set --extended-glob
# prevent redirections from overwriting existing files
set --no-clobber
# don't implicitly expand non-existent variables to empty strings
set --no-unset
# if yash is built with command history enabled...
if command --identify --builtin-command history >/dev/null; then
# don't save commands starting with a space in history
set --hist-space
fi
# if yash is built with line-editing enabled...
if command --identify --builtin-command bindkey >/dev/null; then
# print job status update ASAP, but only while line-editing
set --notify-le
# some terminfo data are broken; meta flags have to be ignored for UTF-8
set --le-no-conv-meta
# enable command line prediction
set --le-predict
set --emacs
# some useful key bindings
bindkey --emacs '\^N' beginning-search-forward
bindkey --emacs '\^O' clear-candidates
bindkey --emacs '\^P' beginning-search-backward
bindkey --emacs '\N' complete-next-column
bindkey --emacs '\P' complete-prev-column
fi
# some useful shortcuts
alias r='fc -s'
# normally yash is more POSIX-compliant than /bin/sh :-)
sh() { yash --posix "$@"; }
yash() { command yash "$@"; }
# By re-defining 'yash' using the 'command' built-in, the 'jobs' built-in
# prints a command name that exposes the arguments like
# 'yash --posix -n foo.sh' rather than a command name that hides the
# arguments like 'yash --posix "${@}"'. This applies to the 'yash' command
# invoked via the 'sh' function.
# ensure job control works as expected
case $- in (*m*)
trap - TSTP TTIN TTOU
esac
# This should be set by $HOME/.config/shrc...
: ${PAGER:=less} ${EDITOR:=vi} ${FCEDIT:=$EDITOR}
: ${LOGNAME:=$(logname)} ${HOSTNAME:=$(uname -n)}
# variables needed for command history
HISTFILE=~/.config/yash/yash_history HISTSIZE=5000
# HISTRMDUP makes prediction less accurate
# HISTRMDUP=500
# emulate bash's $SHLVL
if [ "${_old_shlvl+set}" != set ]; then
_old_shlvl=${SHLVL-}
fi
SHLVL=$((_old_shlvl+1)) 2>/dev/null || SHLVL=1
export SHLVL
# initialize event handlers
COMMAND_NOT_FOUND_HANDLER=()
PROMPT_COMMAND=()
YASH_AFTER_CD=()
# define prompt. this should be done by $HOME/.config/shrc
_hc='\fg.' # green hostname for local
_uc=$_hc _hc= # same username color as hostname for non-root user
# The main prompt ($YASH_PS1) contains the username, hostname, working
# directory, last exit status (only if non-zero), and $SHLVL (only if
# non-one).
YASH_PS1=''$_hc'\fd.''d:${${${PWD:/~/\~}##*/}:-$PWD} e:${{?:/0/}:+\\fr.$?\\fd.} ${{SHLVL-0}:/1} do> '
YASH_PS1R='\fc.${_vcs_info}'
YASH_PS1S='\fo.'
YASH_PS2=$'> '
YASH_PS2S=$YASH_PS1S
YASH_PS4='\fm.+ '
YASH_PS4S='\fmo.'
unset _hc _uc
# No escape sequences allowed in the POSIXly-correct mode.
PS1='${LOGNAME}@${HOSTNAME%%.*} '$PS1
# find escape sequence to change terminal window title
case "$TERM" in
(xterm|xterm[+-]*|gnome|gnome[+-]*|putty|putty[+-]*|cygwin)
_tsl='\033];' _fsl='\a' ;;
(*)
_tsl=$( (tput tsl 0; echo) 2>/dev/null |
sed -e 's;\\;\\\\;g' -e 's;;\\033;g' -e 's;;\\a;g' -e 's;%;%%;g')
_fsl=$( (tput fsl ; echo) 2>/dev/null |
sed -e 's;\\;\\\\;g' -e 's;;\\033;g' -e 's;;\\a;g' -e 's;%;%%;g') ;;
esac
# if terminal window title can be changed...
if [ "$_tsl" ] && [ "$_fsl" ]; then
# set terminal window title on each prompt
_set_term_title()
if [ -t 2 ]; then
printf "$_tsl"'%s@%s:%s'"$_fsl" "${LOGNAME}" "${HOSTNAME%%.*}" \
"${${PWD:/$HOME/\~}/#$HOME\//\~\/}" >&2
fi
PROMPT_COMMAND=("$PROMPT_COMMAND" '_set_term_title')
cmd() {
if [ -t 2 ]; then printf "$_tsl""$0 %s""$_fsl" "$*" >&2; fi
command $0 "$@"
}
# reset window title when invoking long-running programs
ssh() {
if [ -t 2 ]; then printf "$_tsl"'ssh %s'"$_fsl" "$*" >&2; fi
command ssh "$@"
}
tine() {
printf "$_tsl""tine %s""$_fsl" "$*" >&2
command tine "$@"
}
kiss() {
printf "$_tsl""kiss %s""$_fsl" "$*" >&2
command kiss "$@"
}
fpm() {
printf "$_tsl""fpm %s""$_fsl" "$*" >&2
command fpm "$@"
}
fpv() {
printf "$_tsl""fpv %s""$_fsl" "$*" >&2
command fpv "$@"
}
links() {
printf "$_tsl""links""$_fsl" "$*" >&2
command links "$@"
}
man() {
printf "$_tsl""man %s""$_fsl" "$*" >&2
command man "$@"
}
ed() {
printf "$_tsl""ed %s""$_fsl" "$*" >&2
command ed "$@"
}
less() {
printf "$_tsl""less %s""$_fsl" "$*" >&2
command less "$@"
}
bc() {
printf "$_tsl""bc %s""$_fsl" "$*" >&2
command bc "$@"
}
axel() {
printf "$_tsl""axel %s""$_fsl" "$*" >&2
command axel "$@"
}
ssu() {
printf "$_tsl""ssu %s""$_fsl" "$*" >&2
command ssu "$@"
}
iview() {
printf "$_tsl""iview %s""$_fsl" "$*" >&2
command iview "$@"
}
fi
# define function that updates $_vcs_info and $_vcs_root
_update_vcs_info() {
typeset type branch
{
read --raw-mode type
read --raw-mode _vcs_root
read --raw-mode branch
} <(
exec 2>/dev/null
typeset COMMAND_NOT_FOUND_HANDLER=
while true; do
if [ -e .git ] || [ . -ef "${GIT_WORK_TREE-}" ]; then
printf 'git\n%s\n' "${GIT_WORK_TREE:-$PWD}"
git branch --no-color | sed -n '/^\*/s/^..//p'
exit
elif [ -d .hg ]; then
printf 'hg\n%s\n' "$PWD"
exec cat .hg/branch
elif [ -d .svn ]; then
printf 'svn\n'
_vcs_root=$(svn info --show-item=wc-root)
printf '%s\n' "$_vcs_root"
path=$(svn info --show-item=relative-url)
case $path in
(*/branches/*)
printf '%s\n' "${${path#*/branches/}%%/*}"
esac
exit
fi
if [ / -ef . ] || [ . -ef .. ]; then
exit
fi
cd -P ..
done
)
case "$type#$branch" in
(hg#default) _vcs_info='hg';;
(git#master) _vcs_info='git';;
(*# ) _vcs_info="$type";;
(* ) _vcs_info="$type@$branch";;
esac
}
# update $_vcs_info on each prompt
PROMPT_COMMAND=("$PROMPT_COMMAND" '_update_vcs_info')
# these aliases choose a version controlling program for the current directory
alias _vcs='${${_vcs_info:?not in a version-controlled directory}%%@*}'
alias ci='_vcs commit'
alias co='_vcs checkout'
alias di='_vcs diff'
alias log='_vcs log'
alias st='_vcs status'
alias up='_vcs update'
# when a directory name is entered as a command, treat as "cd"
_autocd()
if [ -d "$1" ]; then
HANDLED=true
cd -- "$@"
break -i
fi
COMMAND_NOT_FOUND_HANDLER=("$COMMAND_NOT_FOUND_HANDLER" '_autocd "$@"')
# treat command names starting with % as "fg"
_autofg()
if [ $# -eq 1 ]; then
case $1 in (%*)
HANDLED=true
fg "$1"
break -i
esac
fi
COMMAND_NOT_FOUND_HANDLER=("$COMMAND_NOT_FOUND_HANDLER" '_autofg "$@"')
# print file type when executing non-executable files
_file_type()
if [ -e "$1" ] && ! [ -d "$1" ]; then
file -- "$1"
fi
COMMAND_NOT_FOUND_HANDLER=("$COMMAND_NOT_FOUND_HANDLER" '_file_type "$@"')
. /etc/profile