dotfiles

A steaming hot pile of sh...ell scripts and configuration files.
git clone https://kaka.farm/~git/dotfiles
Log | Files | Refs

dotfiles.org (16214B)


      1 * dot files
      2 :PROPERTIES:
      3 :header-args: :tangle-mode '#o600' :noweb yes :comments noweb
      4 :END:
      5 
      6 ** README
      7 
      8 You might find mirrors in the following addresses:
      9 
     10 - <https://bitbucket.org/yuvallanger/dotfiles>
     11 - <https://gitgud.io/yuvallanger/dotfiles>
     12 - <https://github.com/yuvallanger/dotfiles>
     13 - <https://gitlab.com/yuvallanger/dotfiles>
     14 
     15 ** desktop
     16 *** bash
     17 **** bash_aliases
     18 
     19 #+BEGIN_SRC sh :tangle ~/.bash_aliases
     20   # enable color support of ls and also add handy aliases
     21   if [ -x /usr/bin/dircolors ]; then
     22       test -r ~/.dircolors
     23       if [[ $? == 0 ]]; then
     24           eval "$(dircolors -b ~/.dircolors)";
     25       else
     26           eval "$(dircolors -b)"
     27       fi
     28       alias ls='ls --color=auto'
     29       #alias dir='dir --color=auto'
     30       #alias vdir='vdir --color=auto'
     31 
     32       alias grep='grep --color=auto'
     33       alias fgrep='fgrep --color=auto'
     34       alias egrep='egrep --color=auto'
     35   fi
     36 
     37   # some more ls aliases
     38   alias ll='ls -alF'
     39   alias la='ls -A'
     40   alias l='ls -CF'
     41 
     42   # Add an "alert" alias for long running commands.  Use like so:
     43   #   sleep 10; alert
     44   alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
     45 
     46   alias g=git
     47   alias gl='g l'
     48   alias gs='g s'
     49   alias gc='g c'
     50   alias gd='g d'
     51 
     52   alias e="emacsclient -a= -c"
     53 
     54   alias hebdate="hdate --hebrew|cut -f 3 -d ','|grep -v '^$'"
     55   alias emptify="truncate -c -s 0"
     56 
     57   function pip3fr () { pip3 freeze --user; }
     58   function pip3i () { pip3 install --user --upgrade $@; }
     59   function pip3up () { pip3i "$( pip3fr | sed 's#==.*##' )"; }
     60   function pip3un () { pip3 uninstall "$*"; }
     61 
     62   # http://cs-syd.eu/posts/2015-06-21-gtd-with-taskwarrior-part-2-collection.html
     63   function inn () { task add +in $@; }
     64   function tickle () {
     65           deadline="$1"
     66           shift
     67           inn +tickle wait:"$deadline" "$*"
     68   }
     69   alias tick=tickle
     70   alias think='tickle +1d'
     71 
     72   alias tracli="transmission-remote-cli"
     73   alias trarem="transmission-remote"
     74 
     75   function ppgrep ()
     76   {
     77           if [[ $1 == "" ]];
     78           then
     79                   PERCOL=percol
     80           else
     81                   PERCOL="percol --query $1"
     82           fi
     83           ps aux | eval "$PERCOL" | awk '{ print $2 }'
     84   }
     85 
     86   function ppkill ()
     87   {
     88           if [[ $1 =~ ^- ]];
     89           then
     90                   QUERY=""
     91           else
     92                   QUERY=$1
     93                   [[ $# -gt 0 ]] && shift
     94           fi
     95           ppgrep $QUERY | xargs kill $*
     96   }
     97 #+END_SRC
     98 
     99 **** bashrc
    100 
    101 #+begin_src sh :tangle ~/.bashrc
    102   #!/bin/bash
    103 
    104   # ~/.bashrc: executed by bash(1) for non-login shells.
    105   # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
    106   # for examples
    107 
    108 
    109   if [ -d "$HOME/.local/bin" ] ; then
    110           export PATH="$HOME/.local/bin:$PATH"
    111   fi
    112 
    113   if [ -d "$HOME/bin" ] ; then
    114           export PATH="$HOME/bin:$PATH"
    115   fi
    116 
    117   # If not running interactively, don't do anything
    118   case $- in
    119       ,*i*) ;;
    120       ,*) return;;
    121   esac
    122 
    123   # don't put duplicate lines or lines starting with space in the history.
    124   # See bash(1) for more options
    125   HISTCONTROL=ignoreboth
    126 
    127   # append to the history file, don't overwrite it
    128   shopt -s histappend
    129 
    130   # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
    131   HISTSIZE=1000
    132   HISTFILESIZE=2000
    133 
    134   # check the window size after each command and, if necessary,
    135   # update the values of LINES and COLUMNS.
    136   shopt -s checkwinsize
    137 
    138   # If set, the pattern "**" used in a pathname expansion context will
    139   # match all files and zero or more directories and subdirectories.
    140   #shopt -s globstar
    141 
    142   # make less more friendly for non-text input files, see lesspipe(1)
    143   [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
    144 
    145   # set variable identifying the chroot you work in (used in the prompt below)
    146   [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ] && debian_chroot="$(cat /etc/debian_chroot)"
    147 
    148   # set a fancy prompt (non-color, unless we know we "want" color)
    149   case "$TERM" in
    150       xterm-color|*-256color) color_prompt=yes;;
    151   esac
    152 
    153   # uncomment for a colored prompt, if the terminal has the capability; turned
    154   # off by default to not distract the user: the focus in a terminal window
    155   # should be on the output of commands, not on the prompt
    156   force_color_prompt=""
    157 
    158   if [ -n "${force_color_prompt}" ]; then
    159       if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
    160           # We have color support; assume it's compliant with Ecma-48
    161           # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
    162           # a case would tend to support setf rather than setaf.)
    163           color_prompt=yes
    164       else
    165           color_prompt=
    166       fi
    167   fi
    168 
    169   if [ "$color_prompt" = yes ]; then
    170       PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    171   else
    172       PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    173   fi
    174   unset color_prompt force_color_prompt
    175 
    176   # If this is an xterm set the title to user@host:dir
    177   case "$TERM" in
    178   xterm*|rxvt*)
    179       PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    180       ;;
    181   ,*)
    182       ;;
    183   esac
    184 
    185   # enable color support of ls and also add handy aliases
    186   if [ -x /usr/bin/dircolors ]; then
    187       if [ -r ~/.dircolors ];
    188       then
    189           eval "$(dircolors -b ~/.dircolors)"
    190       else
    191           eval "$(dircolors -b)"
    192       fi
    193       alias ls='ls --color=auto'
    194       #alias dir='dir --color=auto'
    195       #alias vdir='vdir --color=auto'
    196 
    197       alias grep='grep --color=auto'
    198       alias fgrep='fgrep --color=auto'
    199       alias egrep='egrep --color=auto'
    200   fi
    201 
    202   # colored GCC warnings and errors
    203   #export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
    204 
    205   # some more ls aliases
    206   alias ll='ls -alF'
    207   alias la='ls -A'
    208   alias l='ls -CF'
    209 
    210   # Add an "alert" alias for long running commands.  Use like so:
    211   #   sleep 10; alert
    212   alias alert='notify-send --urgency=low -i "$( [ $? = 0 ] && echo terminal || echo error ; )" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
    213 
    214   # Alias definitions.
    215   # You may want to put all your additions into a separate file like
    216   # ~/.bash_aliases, instead of adding them here directly.
    217   # See /usr/share/doc/bash-doc/examples in the bash-doc package.
    218 
    219   if [ -f ~/.bash_aliases ];
    220   then
    221       # shellcheck source=.bash_aliases
    222       source "$HOME/.bash_aliases"
    223   fi
    224 
    225   export PYTHONPATH="$HOME/.local/lib/python3.6:$PYTHONPATH"
    226 
    227   if [ -d "$HOME/gopath" ] ; then
    228           export GOPATH="$HOME/gopath"
    229           export PATH="$GOPATH/bin:$PATH"
    230   fi
    231 
    232   # enable programmable completion features (you don't need to enable
    233   # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
    234   # sources /etc/bash.bashrc).
    235   if ! shopt -oq posix; then
    236     if [ -f /usr/share/bash-completion/bash_completion ]; then
    237       source /usr/share/bash-completion/bash_completion
    238     elif [ -f /etc/bash_completion ]; then
    239       source /etc/bash_completion
    240     fi
    241   fi
    242   if [ -r ~/.byobu/prompt ];
    243   then
    244       # shellcheck source=.byobu/prompt
    245       source "$HOME/.byobu/prompt"   #byobu-prompt#
    246   fi
    247 
    248   # For pipenv and virtualenvwrapper
    249   if [ -d "$HOME/.virtualenvs" ]; then
    250           export WORKON_HOME="$HOME/.virtualenvs"
    251   fi
    252   #export VIRTUALENVWRAPPER_PYTHON="/usr/bin/python3.6"
    253   if [ -f "$HOME/.local/binvirtualenvwrapper_lazy.sh" ]; then
    254       # shellcheck source=.local/bin/virtualenvwrapper_lazy.sh
    255       source "$HOME/.local/bin/virtualenvwrapper_lazy.sh"
    256   fi
    257 
    258   if [ -f "$HOME/.local/bin/find_pycompletion.sh" ]; then
    259       # shellcheck source=.local/bin/find_pycompletion.sh
    260       source "$(find_pycompletion.sh)"
    261   fi
    262 
    263   # https://unix.stackexchange.com/questions/72086/ctrl-s-hang-terminal-emulator
    264   stty -ixon
    265 
    266   printf "And now for something completely different:\n\n"
    267   fortune -c -a | sed 's/^/    /'
    268   printf "\n"
    269 #+end_src
    270 
    271 *** bin
    272 **** xpwgen
    273 
    274 #+begin_src sh :tangle ~/bin/xpwgen :tangle-mode '#o700'
    275   #!/bin/bash
    276 
    277   function make_stripped_password(){
    278       python3 -c """
    279   import sys
    280   print(sys.stdin.read().strip(), end='')
    281   """ <<EOF
    282   $( pwgen -B1 16 )
    283   EOF
    284   }
    285 
    286   make_password | pee 'xsel' 'xsel -b'
    287 #+end_src
    288 
    289 **** qrfeh
    290 
    291 #+begin_src sh :tangle ~/bin/qrfeh :tangle-mode '#o700'
    292   #!/bin/sh
    293 
    294   qrencode -o - "$@" | feh -
    295 #+end_src
    296 
    297 **** glock
    298 
    299 #+begin_src sh :tangle ~/bin/glock :tangle-mode '#o700'
    300   #!/bin/sh
    301 
    302   gnome-screensaver-command --lock
    303 #+end_src
    304 
    305 **** e
    306 
    307 #+begin_src sh :tangle ~/bin/e :tangle-mode '#o700'
    308   #!/bin/sh
    309 
    310   emacsclient -a= -c
    311 #+end_src
    312 
    313 **** upgrade-pip-packages
    314 
    315 #+begin_src sh :tangle ~/bin/upgrade-pip-packages :tangle-mode '#o700'
    316   #!/bin/bash
    317 
    318   userpip="$HOME/.local/bin/pip"
    319 
    320   pip3 install -U --user pip
    321   pip install -U --user pip
    322   "$userpip" install -U --user pipsi
    323   "$userpip" install -U --user pip-tools
    324 
    325   #pip-compile --generate-hashes -v -U --annotate "$HOME/requirements.in"
    326   pip-compile -v "$HOME/requirements.in"
    327   "$userpip" install --user --upgrade -r "$HOME/requirements.txt"
    328 
    329   while read -r a_line
    330   do
    331       declare -A row="$a_line"
    332       pipsi install --python "${row[python]}" "${row[package]}" || pipsi install "${row[package]}"
    333       pipsi upgrade "${row[package]}"
    334   done < "$HOME/pipsi-list"
    335 #+end_src
    336 
    337 **** pxsel - piping in all the clipboards
    338 
    339 #+begin_src sh :tangle ~/bin/pxsel :tangle-mode '#o700'
    340   #!/bin/bash
    341 
    342   pee 'xsel -b' xsel
    343 #+END_SRC
    344 
    345 *** git
    346 **** gitconfig
    347 
    348 #+BEGIN_SRC conf :tangle ~/.gitconfig
    349   [user]
    350           name = Yuval Langer
    351           email = yuval.langer@gmail.com
    352   [gui]
    353           fontdiff = -family Inconsolata -size 16 -weight normal -slant roman -underline 0 -overstrike 0
    354   [core]
    355           editor = vim
    356           excludesfile = ~/.gitignore_global
    357           whitespace = tab-in-indent, trailing-space
    358   [diff]
    359           tool = diff
    360   [difftool]
    361           tool = meld
    362   [alias]
    363           s = status
    364           lg = log --all --graph --decorate --color
    365           c = checkout
    366           d = diff
    367           df = diff --word-diff
    368           l = log --all --graph --decorate --oneline
    369           hash = rev-parse HEAD
    370   [mergetool]
    371           cmd = meld "$LOCAL" "$MERGED" "$REMOTE"
    372   [push]
    373           default = simple
    374   [merge]
    375           tool = meld
    376   [color]
    377           ui = true
    378 #+END_SRC
    379 
    380 **** global gitignore
    381 
    382 #+BEGIN_SRC conf :tangle ~/.gitignore_global
    383   # Compiled source #
    384   ###################
    385   ,*.com
    386   ,*.class
    387   ,*.dll
    388   ,*.exe
    389   ,*.o
    390   ,*.so
    391 
    392   # Packages #
    393   ############
    394   # it's better to unpack these files and commit the raw source
    395   # git has its own built in compression methods
    396   ,*.7z
    397   ,*.dmg
    398   ,*.gz
    399   ,*.iso
    400   ,*.jar
    401   ,*.rar
    402   ,*.tar
    403   ,*.zip
    404 
    405   # Logs and databases #
    406   ######################
    407   ,*.log
    408   ,*.sql
    409   ,*.sqlite
    410 
    411   # OS generated files #
    412   ######################
    413   .DS_Store
    414   .DS_Store?
    415   ._*
    416   .Spotlight-V100
    417   .Trashes
    418   ehthumbs.db
    419   Thumbs.db
    420 
    421   # Byte-compiled / optimized / DLL files
    422   __pycache__/
    423   ,*.py[cod]
    424 
    425   # C extensions
    426   ,*.so
    427 
    428   # Distribution / packaging
    429   bin/
    430   build/
    431   develop-eggs/
    432   dist/
    433   eggs/
    434   lib/
    435   lib64/
    436   parts/
    437   sdist/
    438   var/
    439   ,*.egg-info/
    440   .installed.cfg
    441   ,*.egg
    442 
    443   # Installer logs
    444   pip-log.txt
    445   pip-delete-this-directory.txt
    446 
    447   # Unit test / coverage reports
    448   .tox/
    449   .coverage
    450   .cache
    451   nosetests.xml
    452   coverage.xml
    453 
    454   # Translations
    455   ,*.mo
    456 
    457   # Mr Developer
    458   .mr.developer.cfg
    459   .project
    460   .pydevproject
    461 
    462   # Rope
    463   .ropeproject
    464 
    465   # Django stuff:
    466   ,*.log
    467   ,*.pot
    468 
    469   # Sphinx documentation
    470   docs/_build/
    471 
    472   local_settings.py
    473 #+END_SRC
    474 
    475 *** emacs
    476 **** org-mode
    477 
    478 A list of all agenda files.
    479 
    480 #+BEGIN_SRC conf :tangle ~/.agenda_files
    481   ~/foo/orgmode/main.org
    482   ~/foo/orgmode/notes.org
    483   ~/mine/orgmode/personal.org
    484 #+END_SRC
    485 
    486 *** xmonad
    487 
    488 #+begin_src haskell :tangle ~/.xmonad/xmonad.hs
    489   module Main where
    490 
    491   import           Data.Monoid                  (All)
    492   import qualified DBus                         as D
    493   import qualified DBus.Client                  as D
    494   import           Graphics.X11.Xlib.Extras     (Event)
    495   import           XMonad
    496       ( Choose
    497       , Full
    498       , KeyMask (..)
    499       , KeySym (..)
    500       , Mirror
    501       , Modifier (..)
    502       , MonadIO (..)
    503       , Tall
    504       , Window
    505       , controlMask
    506       , defaultConfig
    507       , handleEventHook
    508       , layoutHook
    509       , mod1Mask
    510       , mod2Mask
    511       , mod3Mask
    512       , mod4Mask
    513       , modMask
    514       , shiftMask
    515       , spawn
    516       , startupHook
    517       , xK_Print
    518       , xK_p
    519       , xK_Return
    520       , xK_i
    521       , xK_z
    522       , xmonad
    523       , (.|.)
    524       , (<+>)
    525       )
    526   import           XMonad.Core                  (X, logHook)
    527   import           XMonad.Hooks.DynamicLog
    528       ( defaultPP
    529       , dynamicLogString
    530       , xmonadPropLog
    531       )
    532   import           XMonad.Hooks.EwmhDesktops    (ewmh, fullscreenEventHook)
    533   import           XMonad.Hooks.ManageDocks     (AvoidStruts, avoidStruts)
    534   import           XMonad.Layout.LayoutModifier (ModifiedLayout)
    535   import           XMonad.Util.EZConfig         (additionalKeys)
    536 
    537   myTerminal :: String
    538   myTerminal = "gnome-terminal"
    539 
    540   myBorderWidth :: Int
    541   myBorderWidth = 2
    542 
    543   myStartupHook :: MonadIO m => m ()
    544   myStartupHook = do
    545       spawn "~/bin/xmonadstartup"
    546 
    547   myLayoutHook :: ModifiedLayout AvoidStruts (Choose Tall (Choose (Mirror Tall) Full)) Window
    548   myLayoutHook = avoidStruts $ layoutHook defaultConfig
    549 
    550   myAdditionalKeys ::
    551       MonadIO m =>
    552       [((KeyMask, KeySym), m ())]
    553   myAdditionalKeys =
    554       [ ((mod4Mask .|. shiftMask, xK_z), spawn "xscreensaver-command -lock")
    555       , ((controlMask, xK_Print), spawn "sleep 0.2; scrot -s")
    556       , ((mod4Mask, xK_p), spawn "dmenu_run")
    557       , ((0, xK_Print), spawn "scrot")
    558       -- , ((mod1Mask, xK_Escape), spawn "setxkbmap -option grp:alts_toggle us,il")
    559       -- , ((controlMask .|. shiftMask, xK_Return), spawn "xsel -b | festival --tts")
    560       , ((mod4Mask .|. shiftMask, xK_Return), spawn myTerminal)
    561       ]
    562 
    563   myHandleEventHook :: Graphics.X11.Xlib.Extras.Event -> XMonad.Core.X Data.Monoid.All
    564   myHandleEventHook = handleEventHook defaultConfig <+> fullscreenEventHook
    565 
    566   myLogHook :: X ()
    567   myLogHook = dynamicLogString defaultPP >>= xmonadPropLog
    568 
    569   main :: IO ()
    570   main = do
    571       dbus <- D.connectSession
    572       -- getWellKnownName dbus
    573       xmonad $ ewmh defaultConfig
    574         { handleEventHook = myHandleEventHook
    575         , layoutHook      = myLayoutHook
    576         , logHook         = myLogHook
    577         , modMask         = mod4Mask
    578         , startupHook     = myStartupHook
    579         } `additionalKeys` myAdditionalKeys
    580 #+end_src
    581 
    582 **** xmonad startup script
    583 
    584 #+begin_src sh :tangle ~/bin/xmonadstartup :tangle-mode '#o700'
    585   #!/usr/bin/env bash
    586 
    587   keynav &
    588   setxkbmap -option -option terminate:ctrl_alt_bksp -option grp:caps_toggle us,il &
    589   redshift &
    590   nm-applet &
    591   xfce4-power-manager &
    592   xfce4-volumed &
    593   trayer &
    594   xmobar &
    595   if [ -f "$HOME/.local/bin/arbtt-capture" ];
    596   then
    597          "$HOME/.local/bin/arbtt-capture" &
    598   else
    599           arbtt-capture &
    600   fi
    601 #+end_src
    602 
    603 *** redshift
    604 
    605 #+begin_src conf :tangle ~/.config/redshift.conf :comments no
    606   [redshift]
    607   temp-day=5700
    608   temp-night=1500
    609   gamma=0.8
    610   adjustment-method=randr
    611   location-provider=manual
    612 
    613   [manual]
    614 
    615   lat=32.07
    616   lon=34.76
    617 #+end_src
    618 
    619 *** youtube-dl
    620 
    621 #+begin_src conf :tangle ~/.config/youtube-dl/config :comments no
    622   -c
    623   -i
    624   --output "~/Downloads/youtube-dl/%(extractor)s/%(uploader_id)s/%(upload_date)s--%(title)s--%(id)s.%(ext)s"
    625   --external-downloader aria2c
    626   --external-downloader-args "--max-connection-per-server=16 --split=16"
    627 #+end_src
    628 
    629 ** termux
    630 *** shortcuts
    631 **** org-add-note
    632 
    633 #+begin_src sh :tangle ~/.shortcuts/org-add-note :tangle-mode '#o700'
    634   emacsclient -a= ~/mine/orgmode/notes.org
    635 #+end_src
    636 
    637 *** bin
    638 
    639 #+begin_src sh :tangle ~/.shortcuts/termux-url-opener :tangle-mode '#o700'
    640   fbreader_save_dir="$HOME/storage/shared/Books/web2fbreader"
    641   url="$1"
    642   printf "book, img, vid, msc? "
    643   cmd="$(python3 -c 'print(input())')"
    644   case "$cmd" in
    645           book) curl -o "${fbreader_save_dir}/$(date --rfc-3=sec).html" "$url";;
    646           img) cd "${img_save_dir}" && wget -m -np -l 1 "$url";;
    647           vid) cd "${vid_save_dir}" && wget -m -np -l 1 "$url";;
    648           msc) cd "${music_save_dir}" && wget -m -np -l 1 "$url";;
    649   esac
    650 #+end_src