Arsenal de shell

Martin Tourneboeuf

November 17, 2020

Tabla de contenidos

1. Nota

         Sistema, Configuración, Nota

2. Shell

         Readline, Bash, Zsh

3. Edición

         Vim y Git

4. Viaje

         Tmux, Fsf, Rg

Entrenarse

Image not found

Afilar

Image not found

No precipitarse

Image not found

Notar

Image not found

Evernote

Image not found

Vimwiki

Image not found

1 presentation.md 2 script.md X
1 ---
2 title: Arsenal de shell
3 author: Tinmarino
4 description: Quien quiere la paz, prepara ... la paz!
Los patrones de código se aplican desde la más humilde
linea.
5 date: Novermber 14, 2020
6 make: pandoc -s --webtex -t slidy presentation.md -o
presentation.html
7 slidy-url: ../res/slidy
8 header-includes: |
9 <link rel="stylesheet" type="text/css" href="../res/
asciinema-player.css" />
10 <script src="../res/asciinema-player.js"></script>
11 <link rel="stylesheet" type="text/css" href="../res/
main-style.css" />
12 ---
13
14 ### Tabla de contenidos [22] ---------------------------
36 ### Entrenarse [12] ------------------------------------
48 ### Afilar [7] -----------------------------------------
55 ### No precipitarse [7] --------------------------------
62 ### Notar [7] ------------------------------------------
69 ### Evernote [7] ---------------------------------------
76 ### Vimwiki [24] ---------------------------------------
100 ### No repetir [7] -------------------------------------
107 ### Readline [9] ---------------------------------------
116 ### Bash [123] -----------------------------------------
239 ### Vim [168] ------------------------------------------
407 ### Vim Plugin [12] ------------------------------------
419 ### Vim Vimspector [10] --------------------------------
429 ### Git [8] --------------------------------------------
437 ### Ahorar tu cerebro [7] ------------------------------
444 ### Hacerlo de tu forma [11] ---------------------------
455 ### Simplificar [7] ------------------------------------
462 ### Tmux [10] ------------------------------------------
472 ### Fzf [9] --------------------------------------------
481 ### Rg<sup style="font-size:50%;"><a href="#foo [34] --
515 ### Mas [33] -------------------------------------------
548 ### Enlace [56] ----------------------------------------

No repetir

Image not found

Readline

Bash

Alias

alias mgr='su - almamgr'
alias op='su - almaop'

Variable

¡No dejes tu prompt[1] definirte, define tu prompt!

¿Qué debe contener un PS1[2]?

[1] Prompt: Indicador de commando

[2] PS1: Prompt String One

Image not found

Image not found

Image not found

Image not found

Image not found

command_not_found_handle

command_not_found_handle() {
  echo "Buuuu! I don't know command $1"
}
export -f command_not_found_handle

comando_malo
# OUTPUTS: Buuu ... comando_malo

Funciones: más que alias

function w () {
  if [[ -z "$1" ]]; then vim -c"call Windex(1)"
  else vim -c"call Windex(1)" -c":VimwikiGoto $1"
  fi
}
# Para ver las funciones definidas
typeset -f

Comandos: más que funciones

Definir sus propios commands en ~/.local/bin

Vim

Mi precioso

noremap s :update!<CR>

¿De que sirve el “s” (por defecto)?

¿Lo tienes mapeado?

¿Usas el “s” por defecto?

¿Porque no lo tienes mapeado?

A mano

let mapleader = ','
let maplocalleader = ','

¿Quién usa otro (delatenlo)?

Las cifras

" Foldlevel <- z
map z1  :set foldlevel=0<CR><Esc>
" ...
map z9  :set foldlevel=8<CR><Esc>

" Tab <- g (like gt and gT builtin: "Goto Tab")
noremap g1 :1tabnext<CR><Esc>
" ...
noremap g9 :9tabnext<CR><Esc>

¿Tienes ejemplos de uso de las teclas con cifras?

Plugin asincrónico

" Define: Lazy loader
function! TimerPack(timer) abort
  packadd ale
  packadd vimwiki
  " Youcompleteme: is verbose at init if no python
  try
    python3 '42'
    " Deletes the vim intro screen
    packadd youcompleteme
  catch | endtry
endfunction

" Call it
if has('timers')
  call timer_start(0, 'TimerPack')
else
  call TimerPack(42)
endif

¿Cómo manejas tus plugins?

Plugin justo a tiempo

noremap <leader>n :silent packadd devicons <CR>:silent packadd nerdtree <CR>:call NERDTreeToogle()<CR>
noremap <leader>u :silent packadd undotree <CR>:UndotreeToggle<CR>

¿Qué plugin cargas justo a tiempo?

Configuración genérica

filetype plugin indent on | syntax on
set encoding=utf-8 | scriptencoding uft-8
set mouse=a

if has('persistent_undo')
  set undodir=$HOME/.vim/undo
  set undofile
endif

¿Te gustaría que este instalado en almamgr?

Trucos

w ! sudo tee %
windo diffthis

¿Qué hace eso?

Vim Plugin

Vim Vimspector

Git

Ahorrar tu cerebro

Image not found

Hacerlo de tu forma

Image not found

Simplificar

Image not found

Tmux

Fzf

Rg[1]

Grep in parallel .. and in Rust

~/Test/ripgrep-0.7.1-------------------------------------
$ rg fast README.md # Args: regex files*
75: faster than both. (N.B. It is not, strictly speaking, a "drop-in" replacement
119:### Is it really faster than everything else?
124:Summarizing, `ripgrep` is fast because:
129: optimizations to make searching very fast.
~/Test/ripgrep-0.7.1-------------------------------------
$ rg 'fn write\\(' # Recursive by default
src/printer.rs
469: fn write(&mut self, buf: &[u8]) {
termcolor/src/lib.rs
227: fn write(&mut self, b: &[u8]) -> io::Result<usize> {
250: fn write(&mut self, b: &[u8]) -> io::Result<usize> {
~/Test/ripgrep-0.7.1-------------------------------------
$ rg clap -g '*.toml' # Glob for filename
Cargo.toml
35:clap = "2.26"
51:clap = "2.26"
~/Test/ripgrep-0.7.1-------------------------------------
$ rg clap -g '!*.toml' # Also negative glob
build.rs
2:extern crate clap;
9:use clap::Shell;
src/app.rs
3:use clap::{App, AppSettings, Arg, ArgSettings};
39:/// Build a clap application parameterized by usage strings.
~/Test/ripgrep-0.7.1-------------------------------------
$ rg fast README.md -r NEW # Replace match (--replace)
75: NEWer than both. (N.B. It is not, strictly speaking, a "drop-in" replacement
88: color and full Unicode support. Unlike GNU grep, `ripgrep` stays NEW while
119:### Is it really NEWer than everything else?
124:Summarizing, `ripgrep` is NEW because:
129: optimizations to make searching very NEW.
~/Test/ripgrep-0.7.1-------------------------------------
$ rg 'fast\s+(\w+)' README.md -r 'NEW-$1-'
> `# Replace submatch` \
> `# rg will never modify your files, but sed can:` \
> `# rg 'fast\s+(\w+)' -l | xargs sed -i -E 's/fast\s+(\w+)/NEW-\1-/g'`
> `# rg 'fast\s+(\w+)' -l | xargs sed -i -E 's/fast\s+(\w+)/NEW-\1-/g'`
88: color and full Unicode support. Unlike GNU grep, `ripgrep` stays NEW-while-
124:Summarizing, `ripgrep` is NEW-because-:
~/Test/ripgrep-0.7.1-------------------------------------
$ time find ~/wiki/ > /dev/null # Find time (no dot file)
real 0m0.311s
user 0m0.091s
sys 0m0.218s
~/Test/ripgrep-0.7.1-------------------------------------
$ time rg --files ~/wiki/ > /dev/null # Rg time
real 0m0.170s
user 0m0.926s
sys 0m0.910s

[1] RG: RipGrep <= Rest In Peace “Global / Regular Expression / Print” (g/re/p)

Más

Conventiones

Manejar distintos shell

  1. System Window manager: Alt-Tab, Alt-Backtick, Mouse, Ctrl-Alt-fn
  2. Default terminal emulator: Konsole (KDE), Gnome-Terminal, Terminal (Mac)
  3. Install Terminal Emulator: Tilix, Alacritty, (no hay Terminator)
  4. Soft Multiplexing: Screen, Tmux

Enlace

Meta

Shell: Readline y Bash

Commun: Vim y Git

Para buscar configuraciones, dar vuelta en github

Otros: Tmux, Fzf y Rg

System

Manuals