dotfiles

*nix config files
git clone git://git.pyratebeard.net/dotfiles.git
Log | Files | Refs | README

herbstluftwm-miniscratch (2165B)


      1 #!/usr/bin/env bash
      2 
      3 # A script allowing to minimize and un-minimize clients in a LIFO way
      4 # (last minimized client will be un-minimized first).
      5 # 
      6 # `chmod +x unminimize.sh` then call it or add it to `autostart`.
      7 
      8 
      9 Mod=${Mod:-Mod4}
     10 Minimizekey=Shift-s
     11 Unminimizekey=Ctrl-s
     12 # get the absolute path of this script, to call it when minimizing
     13 SCRIPT_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/$(basename "${BASH_SOURCE[0]}")
     14 
     15 hc() { "${herbstclient_command[@]:-herbstclient}" "$@" ;}
     16 
     17 scratchclient=$(hc foreach CLIENT clients. and , echo CLIENT , sprintf ATTRSTR %c.title CLIENT substitute ATTRVALUE ATTRSTR echo ATTRVALUE | \
     18       grep -B1 '^scratchpad$' | head -n1 | awk -F. '{print $NF}')
     19 # 
     20 # initialize minimize and unminimize shortcuts
     21 #
     22 init() {
     23 
     24 
     25    # minimize current window
     26    #hc keybind $Mod-$Minimizekey spawn "$SCRIPT_PATH" minimize
     27 
     28    # unminimize last window of a tag
     29    # if the `my_minimized_age` attribute does not exist (i.e. the window has not been
     30    #  minimized with this script), use arbitrary order to unminimize
     31    LANG=en_US.UTF-8 urxvt -title scratchpad -cd /home/pyratebeard -e vim ~/tmp/scratch &
     32    sleep 1
     33    scratchclient=$(hc foreach CLIENT clients. and , echo CLIENT , sprintf ATTRSTR %c.title CLIENT substitute ATTRVALUE ATTRSTR echo ATTRVALUE | \
     34          grep -B1 '^scratchpad$' | head -n1 | awk -F. '{print $NF}')
     35 echo $scratchclient
     36    hc bring $scratchclient
     37    hc set_attr clients.$scratchclient.floating true
     38    hc jumpto $scratchclient
     39 }
     40 
     41 
     42 # 
     43 # minimize focused client
     44 #
     45 minimize() {
     46 
     47    hc set_attr clients.$scratchclient.minimized true
     48 
     49 }
     50 maximize() {
     51 
     52    hc set_attr clients.$scratchclient.minimized false
     53    hc bring $scratchclient
     54    hc jumpto $scratchclient
     55 
     56 }
     57 
     58 if hc foreach CLIENT clients. and , echo CLIENT , sprintf ATTRSTR %c.title CLIENT substitute ATTRVALUE ATTRSTR echo ATTRVALUE | \
     59       grep -B1 '^scratchpad$'; then
     60 	if [[ $(hc get_attr clients.$scratchclient.minimized) == "false" ]] ; then
     61 		minimize
     62 	else
     63 		maximize
     64 	fi
     65 else
     66 	init
     67 fi
     68 #[ $(hc get_attr $scratchclient.minimized) == "false" ] && minimize || init
     69 #if [ "$1" = "minimize" ] ; then minimize ; else init ; fi