# -*- conf -*-
# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=10000
SAVEHIST=20000
setopt appendhistory autocd extendedglob nomatch
unsetopt beep notify
bindkey -e
# End of lines configured by zsh-newuser-install
# The following lines were added by compinstall

zstyle ':completion:*' completer _oldlist _expand _complete _match _correct _approximate
zstyle ':completion:*' expand prefix suffix
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' ignore-parents pwd ..
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-suffixes true
zstyle ':completion:*' matcher-list 'r:|[._-]=** r:|=**' 'r:|[._-]=** r:|=**' 'r:|[._-]=** r:|=**' 'l:|=* r:|=*'
zstyle ':completion:*:match:*' original only
zstyle ':completion:*' max-errors 1 numeric
zstyle ':completion:*' menu select=0
zstyle ':completion:*' preserve-prefix '//[^/]##/'
zstyle ':completion:*' select-prompt %l matches - %SScrolling active: current selection at %p%s
zstyle ':completion:*' special-dirs true
zstyle ':completion:*' squeeze-slashes true
zstyle ':completion:*' use-compctl true
zstyle ':completion:*' verbose true
zstyle :compinstall filename '/home/fly5/.zshrc'

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

path=(/usr/local/bin /usr/local/sbin /sbin /usr/sbin /bin /usr/bin /home/kk/bin $path)
typeset -U PATH # remove duplicate entries

# rename help
autoload -U zmv

# compele only command we have
zstyle ':completion:*:functions' ignored-patterns '_*'
# process ids
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*'   force-list always

# killall
zstyle ':completion:*:killall:*' command 'ps -u $USER -o cmd'

# cache (apt and dpkg are slow)
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zsh/cache

# tÃ¤ydentÃ¤Ã¤ tabit myÃ¶s sanan keskeltÃ¤
setopt COMPLETE_IN_WORD

# istunnon komennot historiatiedoston loppuun eikÃ¤ nollata
setopt APPEND_HISTORY

# komennot historiatiedostoon heti ku ne syÃ¶tetty
setopt INC_APPEND_HISTORY

# ei piipata
unsetopt BEEP
setopt nobeep

# GREEN=`tput setaf 2`
# BRIGHTGREEN=`tput bold; tput setaf 2`
# YELLOW=`tput setaf 3`
# BRIGHTYELLOW=`tput bold; tput setaf 3`
# BLACK=`tput setaf 0`
# RED=`tput setaf 1`
# BRIGHTRED=`tput bold; tput setaf 1`
# BLUE=`tput setaf 4`
# MAGENTA=`tput setaf 5`
# CYAN=`tput setaf 6`
# NORM=`tput sgr0`

eval `dircolors -b`
alias d="ls --color"
alias ls="ls --color=auto"
#alias ll="ls --color -l"
alias ls='ls --color=auto'


### bashista konvertoidut aliakset alkaa

#pikkunen funktio tekemaan pienta jalkea
function pieni {
iso="$*"
iso=`echo $iso | tr "[:upper:]" "[:lower:]"`
echo $iso
}

#alias lsf='ls -F --color=tty' #regular ls
alias lsa='ls -la'
alias la='ls -la'
alias lsf='ls *(.)' # only files
alias l.='ls -dF .[a-zA-Z0-9]* --color=tty' #only show dotfiles
alias ll='ls -lhF --color=tty' #long listing
##alias lsd='ls -d */ | xargs -l basename' #dir
alias lsd='ls -d */' #dirs
alias lsdn='ls -ld *(-/DN)' # myos symlinkit ja piilot
alias lsd.='ls -d .[a-zA-Z0-9]*/ --color=tty' # only dot dirs


alias rmi="rm -i"
alias cpi="cp -i"
alias mvi="mv -i"

alias du="du -h"
alias df="df -h"

alias bzip2='bzip2 -v'
alias j=jobs
alias cd..="cd .." #work around a common typo

#Automatically do an ls after each cd
cd() {
  if [ -n "$1" ]; then
    builtin cd "$@" && ls
  else
    builtin cd ~ && ls
  fi
}

alias hist='history | grep $1'

alias lordgame='telnet lord.nuklear.org 10240'

alias funkki='telnet the-funk.net 7000'
alias starwarssi='telnet towel.blinkenlights.nl'

# now they use same command
#service () {
#sudo /etc/init.d/$*
#}

alias etsi='zypper search'
alias asenna='sudo zypper install'
alias poista='sudo zypper remove'
alias nayta='zypper info'
alias paivita='sudo zypper refresh && sudo zypper dup; sudo flatpak update && sudo flatpak uninstall --unused; zypper needs-rebooting'

alias kaantopaiva='LC_ALL=en_US.UTF-8 date +"%a, %-d %b %Y %H:%M:%S %z"'
### bashista konvertoidut aliakset loppuu


### PROMPT ###

BLACK="%{"$'\033[01;30m'"%}"
GREEN="%{"$'\033[01;32m'"%}"
RED="%{"$'\033[01;31m'"%}"
YELLOW="%{"$'\033[01;33m'"%}"
BLUE="%{"$'\033[01;34m'"%}"
BOLD="%{"$'\033[01;39m'"%}"
NORM="%{"$'\033[00m'"%}"
LGREEN="%{"$'\033[0;32m'"%}"

## kivat? varit
#PROMPT="${LGREEN}%m${GREEN}[${LGREEN}%h${GREEN}]${LGREEN}:${BLUE}%~${LGREEN} %#${NORM} "
#PROMPT="${LGREEN}%m${GREEN}[${LGREEN}%n${GREEN}]${LGREEN}:${BLUE}%~${LGREEN} %#${NORM} "
PROMPT="${LGREEN}%n${GREEN}[${LGREEN}%m${GREEN}]${LGREEN}:${BLUE}%~${LGREEN} %#${NORM} "

# oikeen reunan prompti
RPROMPT="${GREEN}(${LGREEN}%T${GREEN})${NORM}"

### /PROMPT ###

# STDERR punasella
#exec 2>>(while read line; do
#print '\e[91m'${(q)line}'\e[0m' > /dev/tty; done &)

# pois flow control (se hairitseva ctrl-s ctrl-q)
stty -ixon

# kaunis ls
alias ls='ls --color=auto'

ZLS_COLORS=$LS_COLORS

# globaaleja aliaksia
alias -g '...'='../..'
alias -g '....'='../../..'
alias -g '.....'='../../../..'

# poistuessa disownataan prosessi ettei sulkeudu
sulje () {
disown %1
exit 0
}

# my less is better than yours :P
#eval "$(lessfile)"

alias avaabash='xterm -C /bin/bash'

# export KDE_NO_IPV6=true

alias nayta-aito="sed -n -e 'l'"
alias pakkaa="tar czf"

# titlefun
# case $TERM in
# 	*xterm*|*rxvt*|(dt|k|E)term)
# 		precmd () { print -Pn "\e]0;$(basename $SHELL): %~\a" }
# 		preexec () { print -Pn "\e]0;$1\a" }
# 		;;
# 	screen)
# 		precmd () { print -Pn "\e]0;$(basename $SHELL):: %~\a" }
# 		preexec () { print -Pn "\e]0;$1\a" }
# esac

#
#preexec () {
#	echo -ne "\ek${(s: :)1[1]}\e\\"
#}

# nethakki() {
# urxvt \
#  +hold \
#  -bg black \
#  -fn "xft:Bitstream Vera Sans Mono:pixelsize=20" \
#  -title "netslas'hem" \
#  -geometry 82x24 \
#  -e ssh purkki \
#  2>/dev/null
# }

#hae() {
#find . -type f -name "$@"
#}

alias -g hae='noglob find . -type f -name "$@"'

# pois
alias c='exec clear ${1+"$@"}'


alias giffit2png='for i in **/*.gif; convert $i $i:r.png'
alias -g deitti='`date +"%F"`'

# downloads
alias lataa='echo "Download dir: `pwd`"; while read line; do wget -q $line 2>/dev/null 1>&2 && echo "OK: \"$line\"" || echo "Error with adr: \"$line\""; done'


alias slashem-ssh="echo -e '\nPassword: slashem\nPeli-tunnus: Katja\n' && TERM=rxvt ssh slashem@slashem.me"

alias smallinfo='echo "$(whoami)@$(hostname) - $(basename $SHELL)@$TERM - $(uname -sr)"'

# fix for the ugly openoffice.org
# export OOO_FORCE_DESKTOP=kde

avi2mpg () {
for i in *; do ffmpeg -i "$i" -target pal-vcd "${i:r}.mpg"; done
}

erikoisetpois () {
zmv '(**/)(*)' '$1${2//[^A-Za-z0-9._]/_}'
}

avimpgpieniks () {
zmv '(**/)(*).(#i)avi' '$1$2.avi'
zmv '(**/)(*).(#i)mpg' '$1$2.mpg'
}


mcd () { mkdir -p -- "$*" && cd "$*" }


alias lsnew=" ls -al --time-style=+%D | grep `date +%D` "
alias dir-in-use="lsof +D"

# for some game installs (after install: unset _POSIX2_VERSION)
# export _POSIX2_VERSION=199209

#alias onecorestart="taskset -c 1"

## http://nion.modprobe.de/blog/archives/569-colored-manpages.html
alias man="TERMINFO=~/.terminfo/ LESS=C TERM=mostlike PAGER=less man"

alias md5password='echo "import getpass, hashlib; print hashlib.md5(getpass.getpass()).hexdigest()" | python -'

# i want space
#sudo setxkbmap -option "nbsp:none"

alias maili="ssh kapsi -t alpine"

alias slashtermi="urxvt +hold -bg black -fn \"xft:Bitstream Vera Sans Mono:pixelsize=20\" -title \"netslas'hem\" -geometry 82x24"

punanenvirhe() {
exec 2>>(while read line; do
print '\e[91m'${(q)line}'\e[0m' > /dev/tty; done &)
}

source /etc/zsh_command_not_found


# List all directories leading up to a filename; this is useful to see
# if some permissions are blocking access to a file.
#
lspath () {
        if [ "$1" = "${1##/}" ]
        then
	    pathlist=(/ ${(s:/:)PWD} ${(s:/:)1})
	else
	    pathlist=(/ ${(s:/:)1})
	fi
        allpaths=()
        filepath=$pathlist[0]
        shift pathlist
        for i in $pathlist[@]
        do
                allpaths=($allpaths[@] $filepath)
                filepath="${filepath%/}/$i"
        done
        allpaths=($allpaths[@] $filepath)
        ls -ld "$allpaths[@]"
}

alias -g ND='$(ls -d *(/om[1]))' # newest directory
alias -g NF='$(ls *(.om[1]))'    # newest file

