# Last change: 14.11.2025, 08:00

# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
bindkey -v
# End of lines configured by zsh-newuser-install
# The following lines were added by compinstall
zstyle :compinstall filename '/home/erik/.zshrc'

autoload -Uz compinit
compinit
# End of lines added by compinstall

setopt prompt_subst
PROMPT='%n@%m:%32<...<%~%<<> '
RPROMPT=%?
PS2='$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT(%_)$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT'

# Decide if we need to set titlebar text.
case $TERM in
	xterm*)
		PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\a%}'
		;;
	screen)
		PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
		;;
		*)
		PR_TITLEBAR=''
		;;
esac

# Decide whether to set a screen title
if [[ "$TERM" == "screen" ]]; then
	PR_STITLE=$'%{\ekzsh\e\\%}'
else
	PR_STITLE=''
fi

# completion
zmodload -i zsh/complist
zstyle ':completion:*' menu select=2
bindkey -M menuselect '^a' accept-and-hold
# case-insensitive (uppercase from lowercase) completion
#zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
## case-insensitive (all) completion
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
## case-insensitive,partial-word and then substring completion
#zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'

# history: always move the cursor to the end of the line
autoload -U history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey '\e[A' history-beginning-search-backward-end
bindkey '\e[B' history-beginning-search-forward-end
bindkey '\eOA' history-beginning-search-backward-end
bindkey '\eOB' history-beginning-search-forward-end

# switch to directory without typing cd
setopt auto_cd

# don't kill programs on logout
setopt nohup

# don't ask if I want to remove I'm sure
setopt rm_star_silent

# correct home/end etc keys
bindkey '\e[2~' quoted-insert
bindkey '\e[3~' delete-char
bindkey '\e[5~' beginning-of-history
bindkey '\e[6~' end-of-history
bindkey '\e[7~' beginning-of-line
bindkey '\e[8~' end-of-line
# fix keys in screen
bindkey '\e[1~' beginning-of-line
bindkey '\e[4~' end-of-line
#case $TERM in (xterm*)
	bindkey '\e[H' beginning-of-line
	bindkey '\e[F' end-of-line
#esac

# force file completion with ^f
zle -C complete complete-word complete-files
bindkey '^f' complete
complete-files () { compadd - $PREFIX* }

# from grml
#
# press esc-e for editing command line in $EDITOR or $VISUAL
autoload -U edit-command-line
zle -N edit-command-line
bindkey '\ee' edit-command-line
#
# Insert last typed word
insert-last-typed-word() { zle insert-last-word -- 0 -1 };
zle -N insert-last-typed-word;
bindkey "\em" insert-last-typed-word
#
# Insert last word
bindkey "\e\." insert-last-word
#
# undo
bindkey "^u" undo

# exports
export PYTHONSTARTUP=~/.pythonrc.py
export EDITOR=vim
export VISUAL=$EDITOR
export EDIT=$EDITOR
export LANG=de_DE@euro
export LC_NUMERIC=C
export GTK2_RC_FILES=~/.gtkrc-2.0
export SDL_VIDEO_X11_DGAMOUSE=0 # qemu 
#export LM_LICENSE_FILE=/opt/Modelsim/license.dat
export PATH=$PATH:/opt/Modelsim/Modeltech_xe_starter/linux:~/bin
export LESS=-Ri # less search case insensitive
export MAILER=icedove
export GCAL="-s1" # start of week=monday

# aliases
alias ls="ls --color=auto"
alias ll="ls -l"
alias ssh="ssh -C -X"
alias less="less -i" # ignore case
#alias opera="opera -notrayicon"
alias mv="mv -i"
alias cp="cp -i"
#alias ise='source /opt/Xilinx/10.1/ISE/settings32.sh; export LD_PRELOAD=/usr/src/modules/usb-driver/libusb-driver.so; ise'
#alias xps='source /opt/Xilinx/10.1/ISE/settings32.sh; source /opt/Xilinx/10.1/EDK/settings32.sh; export LD_PRELOAD=/usr/src/modules/usb-driver/libusb-driver.so; xps'
#alias xps_sdk='source /opt/Xilinx/10.1/ISE/settings32.sh; source /opt/Xilinx/10.1/EDK/settings32.sh; export LD_PRELOAD=/usr/src/modules/usb-driver/libusb-driver.so; xps_sdk'
#alias impact='source /opt/Xilinx/10.1/ISE/settings32.sh; export LD_PRELOAD=/usr/src/modules/usb-driver/libusb-driver.so; impact'
#alias impact_unlock="echo -e 'cleancablelock\nexit' | impact -batch"
#alias ise='source /opt/Xilinx/10.1/ISE/settings32.sh; export XIL_IMPACT_USE_LIBUSB=1; ise'
#alias xps='source /opt/Xilinx/10.1/ISE/settings32.sh; source /opt/Xilinx/10.1/EDK/settings32.sh; export XIL_IMPACT_USE_LIBUSB=1; xps'
#alias impact='source /opt/Xilinx/10.1/ISE/settings32.sh; export XIL_IMPACT_USE_LIBUSB=1; impact'
alias vegatrek="vegastrike -Mvegatrek"
alias ftcmrupload="~/Proggen/python/ftcupload/ftcuploader.py Defiant \"Modelle | Roboter, Industrieanlagen und Computing | Lauf-, Fahr- und Kletterroboter | Defiants MR 2009\""
alias gpe-todo="ssh orinoco 'gpe-todo'"
alias ifup="sudo /sbin/ifup"
alias ifdown="sudo /sbin/ifdown"
alias home_secure="sudo /usr/local/sbin/home_secure"
alias x2x_r2d2="ssh r2d2 x2x -to :0"
alias x2x_mm="ssh mm x2x -to :0"
alias x2x_dp="ssh localhost x2x -from :0 -to :8"
alias encode_h264='ffmpeg -i $infile -f mp4 -vcodec libx264 -profile high -x264opts bframes=0:crf=20 -acodec copy $outfile.mp4'
alias finddupicase='find . | sort -f | uniq -i -d'
alias ssh_proxy='ssh -D 8080'

# global aliases
#alias -g G='| grep -i'
#alias -g L='| less'
#alias -g C='| wc -l'
alias -g vlc_option_out_http="--sout http/ts::8080"
alias -g vlc_option_out_rtsp="--sout '#rtp{sdp=rtsp://0.0.0.0:8080/video}'"

# suffix aliases
alias -s tex=gvim
alias -s html=w3m
#alias -s org=w3m
alias -s txt=gvim
alias -s pdf=xpdf
alias -s ods=ooffice
alias -s odt=ooffice
alias -s c=gvim
alias -s jar=java -jar
ssh-get-audio() {ssh -C $1 sox -q -t alsa plughw:Loopback,1,0 -t wav -b 24 -r 48k - | play -q -}
ssh-put-audio() {sox -q -t alsa plughw:Loopback,1,0 -t wav -b 24 -r 48k - | ssh -C $1 play -q -}

# cd
BAT0=/sys/devices/platform/smapi/BAT0
BAT1=/sys/devices/platform/smapi/BAT1

# mplayer file types
zstyle ':completion:*:mplayer:*' file-patterns "*.(#i)(asf|asx|avi|flac|flv|m1v|m2p|m2v|m4v|mjpg|mka|mkv|mov|mp3|mp4|mpe|mpeg|mpg|ogg|ogm|qt|rm|vob|wav|wma|wmv|ts|tp|m2t|m2ts|m3u|bik|ogv)(-.) *(-/)"
zstyle ':completion:*:mplayer:*' tag-order 'files:urls'

function random_file() {
	FILES=( $@ )
	RANDOM=$(date +%N) # seed with nanoseconds
	echo $FILES[$RANDOM%$#FILES+1]
}

LOCALZSHRC=~/.zshrc_$(hostname)
if [[ -a $LOCALZSHRC ]]; then
	source $LOCALZSHRC
fi

# http://chneukirchen.org/blog/archive/2013/03/10-fresh-zsh-tricks-you-may-not-know.html
if [[ $1 == eval ]]; then
	shift
	ICMD="$@"
	set --
	zle-line-init() {
		BUFFER="$ICMD"
		zle accept-line
		zle -D zle-line-init
	}
	zle -N zle-line-init
fi
