serhii.net

In the middle of the desert you can say anything you want

25 Nov 2020

Day 695

Multiple monitors / productivity idea

If I have a laptop and two external monitors, put the ‘distracting’ things on the laptop monitor and close the laptop. Open it when I’m officially doing a pause.

My aliases for grep and history

I shouldn’t forget that I have g aliased to grep, along with h to history | grep. Just tried this and it works:

h vim | g http

zsh expand all aliases; zsh keybindings; zsh show all files in directory

Added this 1 to ./zshrc:

expand-aliases() {
  unset 'functions[_expand-aliases]'
  functions[_expand-aliases]=$BUFFER
  (($+functions[_expand-aliases])) &&
    BUFFER=${functions[_expand-aliases]#$'\t'} &&
    CURSOR=$#BUFFER
}

zle -N expand-aliases
bindkey '^E' expand-aliases

^E is <C-e>. Gets run anytime I use it, without connection to the written text. Neat.

Also found this in ./.zshrc:

# Usage:
#   In the middle of the command line:
#     (command being typed)<TAB>(resume typing)
#
#   At the beginning of the command line:
#     <SPACE><TAB>
#     <SPACE><SPACE><TAB>
#
# Notes:
#   This does not affect other completions
#   If you want 'cd ' or './' to be prepended, write in your .zshrc 'export TAB_LIST_FILES_PREFIX'
#   I recommend to complement this with push-line-or edit (bindkey '^q' push-line-or-edit)
function tab_list_files
{
  if [[ $#BUFFER == 0 ]]; then
    BUFFER="ls "
    CURSOR=3
    zle list-choices
    zle backward-kill-word
  elif [[ $BUFFER =~ ^[[:space:]][[:space:]].*$ ]]; then
    BUFFER="./"
    CURSOR=2
    zle list-choices
    [ -z ${TAB_LIST_FILES_PREFIX+x} ] && { BUFFER="  "; CURSOR=2; }
  elif [[ $BUFFER =~ ^[[:space:]]*$ ]]; then
    BUFFER="cd "
    CURSOR=3
    zle list-choices
    [ -z ${TAB_LIST_FILES_PREFIX+x} ] && { BUFFER=" "; CURSOR=1; }
  else
    BUFFER_=$BUFFER
    CURSOR_=$CURSOR
    zle expand-or-complete || zle expand-or-complete || {
      BUFFER="ls "
      CURSOR=3
      zle list-choices
      BUFFER=$BUFFER_
      CURSOR=$CURSOR_
    }
  fi
}

zle -N tab_list_files
bindkey '^I' tab_list_files

<C-i> gives a list of files in the directory, and space-space-tab at the beginning of the line too. <C-q> (push-line-or-edit). More about it here: TIL: save half-typed commands in bash and zsh « Serge Gebhardt (sgeb.io) TL;DR remove command currently being edited and paste it at the next Return.

Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus