#-*-sh-*-

alias c="cd ..;ls"
alias cl="rm -f *~ \#*;clear;ll"
alias clt="rm -f *~ \#* *.dvi *.log *.ps *.ps.* *.MAR  *.aux *.toc;clear;ll"
alias f='file -Pelf_phnum=10000'

alias mkd=mkdir
# alias mdk=mkd


alias mq=mailq
alias gu=gunzip
# devel:
alias m=make

# i want ch e  --- expand
alias ch-="chmod g-w"
alias chr="chmods root g-w"

alias ch="chmods mm g+wr"
alias chu="chmods users g+wr"
alias chh="chmods html g+wr"
alias chs="chmods scanner g+wr"
alias cht="chmods tex g+wr"
alias che="chmods emacs g+wr"
alias chf="chmods foto g+wr"
alias chv="chmods video g+wr"
alias cha="chmods audio g+wr"

# alias XX="echo \\\$server > /var/state/where/\$LOGNAME"
alias xx="chmod +x"
alias xx-="chmod -x"
alias xx-.="chmod -x *(.)"




#alias p='ps uww -C'
alias pold='ps -O ppid,user,comm:10,stat,pcpu,pmem  -C'
alias p="pgrep --list-full --list-name --ignore-case --lightweight"


#
alias rmd=rmdir
alias rmdr='find -depth -type d -empty -exec rmdir -v {} \;'


## Archive
alias t="tar -xapf"
alias tb="tar --use-compress-program  bzip2 -xpf"

alias un="untar.scm"
alias z=gzip

##
alias wh="my_which"
# alias xs="xscanimage hp"



## Shell itself
alias pu="pushd ."
alias po="popd"
alias di=dirs

alias h='history -i -10'
alias hh='history -i -100'

if under_zsh;
then
    alias j="jobs -l -p"
else
     alias j="jobs -l"
fi



## pager

# todo: colorful (syntax)
if which myless &> /dev/null;
then
    alias l="myless"
else
    alias l="less"
fi

alias lg='less +G -n'
alias var='tail -20 /var/log/messages'
alias val='less +G -n /var/log/messages'
alias ltl='lt /var/log/'





## ls
# Variants of ls
#----------------
if [ $TERM != dumb ]
then
    ls_color_option=auto
else
    ls_color_option=no
fi

#alias l="ls -l "

# -v puts uppercase before lowercase -- not good.
# or otherwise put that to `ls' too.

alias ls="ls -F --color=$ls_color_option --ignore-backups --literal --sort=version"
alias la="ls --almost-all"

# 2 versions: human or precise:
if which eza;
then
    alias ll="eza -l --ignore-glob '*~'"
    alias lt="ll --sort=time"
    # -r

    # or changed?
    alias lss="ll --sort=size"
    alias lsa="ll --bytes -A --color=$ls_color_option"
else
alias ll="ls -l --color=$ls_color_option --ignore-backups --human-readable"
alias lsa="ls -lA --color=$ls_color_option --ignore-backups"
alias lsab="ls -lA --color=$ls_color_option"

alias llb="- ls -l --color=$ls_color_option --human-readable"
alias lla="ll --almost-all"

# time:
alias lt="ll -tr --time-style=long-iso"
alias ltt="ls -tr"
alias lss="ll -Sr"

# with backup:
alias llb="- ls -l --color=$ls_color_option --human-readable"

# solve symlinks:
alias lll="ll --dereference"
alias lld='ll -d'

# correct:
alias sl=ls
fi

### For security:
alias rm="rm -i"
alias cp="cp -ipa"
alias mv="mv -i"
alias ln="ln -i"
alias rmm="rm -i"
alias rmm="rm -i"
alias rmdirr="find -depth -exec rmdir {} \;"

## Human
alias df="df -h"

if [ -z "$ZSH_VERSION" ]; then
    alias d='find  -mindepth 1  -maxdepth 1  -type d -print0 |xargs  --null du -s -h'  #--max-lines=1
else
# alias dudir="du -s --human-readable *(/)"
    alias d="du -c -x -s --human-readable *(/)"
    alias ds='- du -x -s *(/) |sort -n| human 1024'
# .scm 1024
    alias du='du -hsc'
fi

alias MM="htop -t -s M_RESIDENT"

# bash compati
if under_zsh;
then
   if - grep --version 2>&1 | - grep  -F '2.5e' > /dev/null;
   then
       grep_color="--color"
   else
       grep_color="--color=always"
       # --directories=recurse --exclude='*~' --ignore-case"
   fi
fi

# big loss:
# --directories=recurse
alias grep="grep $grep_color --exclude-dir=.git --exclude='*~' --ignore-case"

alias fsgrep="find | grep"


# ps
if under_zsh;
then
    alias pp='nocorrect ps xauww|grep'
    alias pf='ps -eo user,pid,ni,vsz,comm |grep '
else
    alias pp='ps xauww|grep'
fi



alias mm="mount"
alias umm="umount"


## Rlwrap
alias gosh="rlwrap gosh"
alias goshfv="gosh -fload-verbose"
alias scsh="rlwrap scsh"


alias TT="tail -n 20"
alias T="tail -f"
alias nr=netring

export activity_dir=/home/michal/activity
alias ali=". ${preference_dir}/aliases/top"

# X & high
alias xpdf='xpdf -z 5 '
alias rlpr='rlpr --no-bind  --debug'

alias oo="oowriter2"
alias wwon='sudo wwwoffle -on; sudo wwwoffle -fetch'
alias wwoff='sudo wwwoffle -off'

alias minicom="minicom -C minicom.cap"



alias ffon="killall -CONT   firefox-bin"
alias ffoff="killall -STOP   firefox-bin"

#local variable:
chrome_binary=chromium-browser
#chrome
alias chroff="killall -STOP $chrome_binary"
alias chron="killall -CONT $chrome_binary"
alias chronic="foreach pid (\$(pidof $chrome_binary)) {chrt --idle -p 0 \$pid }"


alias pig="ping google.com"
# google.com=72.14.234.104

alias kl=killall
alias KL="killall -9"
alias KILL="kill -KILL"

alias wg='wget --reject=gif,jpg --recursive --level=0 '
alias mb=modprobe

alias slow='renice -n 10 $$; ionice -c 3 -p $$'


# make it a program?
alias reset_xterm='echo -e "\\033c"'


alias ssh="ssh -Y -A -o VisualHostKey=yes"


# back to using Cron & hence: mail
alias ml=mail
alias fr=from

alias decore="find -type f \\( -name 'core.[0-9]*' -o -name 'core' \\)  -print -exec rm '{}' \\;"

alias net_neighb='for i in {1..255}; do (if ping -c 1  192.168.1.$i > /dev/null; then echo $i; fi)& done'


alias rsync='rsync -a -v --itemize-changes'


alias kconfig_find="find -name 'Kconfig*' -exec grep {} \; -print"


# command `modifiers' -- expand the word after (note the trailing space)
alias NICE="nice -n 18 ionice -c 3 "
alias sudo="sudo "


alias slow='chrt --other -p 0 $$; renice -n 10 $$; ionice -c 3 -p $$'
alias iotop="iotop -o -d 10 -P"



# systemd http://0pointer.de/blog/projects/systemd-for-admins-2.html
alias psc='ps xawf -eo pid,user,cgroup,args'
alias sc='sudo systemctl'



if [[ -n $HISTFILE ]];
then
    alias job="fc -p $(dirname $HISTFILE)"
fi

alias xlock="killall -SIGHUP gpg-agent; xset dpms 10 200 400; xset dpms force standby; xtrlock -b;xset dpms 300 400 500"

alias stop-chrome="killall -STOP chrome"
alias cont-chrome="killall -CONT chrome"

alias stop-firefox="killall -STOP firefox"
alias cont-firefox="killall -CONT firefox"

##
alias ip="=ip -c -br"

# - ip would mean suppress further expansion
# but does it work?   not after sudo !!
# not on ubuntu!
