customizing your shelldirk.eddelbuettel.com/papers/t4_003_shell_customisation.pdf · shell tip 3:...

14
CUSTOMIZING YOUR SHELL COMPOUNDING LOTS OF SMALL CHANGES FOR LARGER EFFECTS Dirk Eddelbuettel T 4 Video Lightning Talk #003 May 24, 2020

Upload: others

Post on 09-Aug-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CUSTOMIZING YOUR SHELLdirk.eddelbuettel.com/papers/t4_003_shell_customisation.pdf · SHELL TIP 3: SOME TIPS AT THE PROMPT How • Briefly: • Applicationscantellbashabouttheircommands

CUSTOMIZING YOUR SHELL

COMPOUNDING LOTS OF SMALL CHANGES FOR LARGER EFFECTS

Dirk Eddelbuettel

T4 Video Lightning Talk #003May 24, 2020

Page 2: CUSTOMIZING YOUR SHELLdirk.eddelbuettel.com/papers/t4_003_shell_customisation.pdf · SHELL TIP 3: SOME TIPS AT THE PROMPT How • Briefly: • Applicationscantellbashabouttheircommands

RECAP

Previously we

• Introduced the series with an overview in episode 000• Started some first shell customization with color in episode 001• Looked into setting up custom shell prompts in episode 002• Showed the GitHub repo t4 for comments, questions etc

T4 Video 2/14

Page 3: CUSTOMIZING YOUR SHELLdirk.eddelbuettel.com/papers/t4_003_shell_customisation.pdf · SHELL TIP 3: SOME TIPS AT THE PROMPT How • Briefly: • Applicationscantellbashabouttheircommands

TODAY

More Shell Customization and Tips

• An alias can save typing• But what else saves typing that have not mentioned?

• TAB completion• Command-line search

• So let’s do those first

T4 Video 3/14

Page 4: CUSTOMIZING YOUR SHELLdirk.eddelbuettel.com/papers/t4_003_shell_customisation.pdf · SHELL TIP 3: SOME TIPS AT THE PROMPT How • Briefly: • Applicationscantellbashabouttheircommands

SHELL TIP 3: SOME TIPS AT THE PROMPT

How

• Briefly:

• Applications can tell bash about their commands• Bash then knows what command arguments are possible• And can complete

• E.g. the R package for Debian/Ubuntu has long carried a filecontributed by Deepayan Sarkar of the R Core team

• DEMO

T4 Video 4/14

Page 5: CUSTOMIZING YOUR SHELLdirk.eddelbuettel.com/papers/t4_003_shell_customisation.pdf · SHELL TIP 3: SOME TIPS AT THE PROMPT How • Briefly: • Applicationscantellbashabouttheircommands

SHELL TIP 4: THOSE KEYBOARD SHORTCUTS

What keys?

• Ctrl-A and Ctrl-E for begin and end of line• Ctrl-R to search command history• Ctrl-L to redraw screen

T4 Video 5/14

Page 6: CUSTOMIZING YOUR SHELLdirk.eddelbuettel.com/papers/t4_003_shell_customisation.pdf · SHELL TIP 3: SOME TIPS AT THE PROMPT How • Briefly: • Applicationscantellbashabouttheircommands

SHELL TIP 4: THOSE KEYBOARD SHORTCUTS

Source: https://wizardzines.com/comics/bash-tricks/

T4 Video 6/14

Page 7: CUSTOMIZING YOUR SHELLdirk.eddelbuettel.com/papers/t4_003_shell_customisation.pdf · SHELL TIP 3: SOME TIPS AT THE PROMPT How • Briefly: • Applicationscantellbashabouttheircommands

SHELL TIP 5: ALIASES

Where?

• Locally ~/.bash_aliases• or any file you source from ~/.bash_profile

• We have already seen how it turned on color for ls• I just keep a few for common commands

T4 Video 7/14

Page 8: CUSTOMIZING YOUR SHELLdirk.eddelbuettel.com/papers/t4_003_shell_customisation.pdf · SHELL TIP 3: SOME TIPS AT THE PROMPT How • Briefly: • Applicationscantellbashabouttheircommands

SHELL TIP 5: ALIASES

Mine

## stterm simpler terminal with 'large enough' font for obs#alias st18='/usr/bin/stterm -f ”Liberation Mono-18”'#alias st20='/usr/bin/stterm -f ”Liberation Mono-20”'

## docker run and mount## use -u `id -u`:`id -g` if unclear what uid:gid to usealias dkrr='docker run --rm -ti -u1000:1000 -v$(pwd):/work -w /work'alias dkrrr='docker run --rm -ti -v$(pwd):/work -w /work'alias dkrrx='docker run --rm -it -u1000:1000 -e DISPLAY=$DISPLAY \

-v /tmp/.X11-unix:/tmp/.X11-unix'

## emacsclient for byobu/tmux/screenalias be='TERM=screen emacsclient -nw'

T4 Video 8/14

Page 9: CUSTOMIZING YOUR SHELLdirk.eddelbuettel.com/papers/t4_003_shell_customisation.pdf · SHELL TIP 3: SOME TIPS AT THE PROMPT How • Briefly: • Applicationscantellbashabouttheircommands

SHELL TIP 5: ALIASES

How does one write an alias?

• Keyword alias followed by key=value• where value can be an expression

• Expression can contain further

• shell commands such as $(pwd)• shell variables such as $DISPLAY

• Simpler than bash functions• Simpler than bash scripts• And obviously more limited too• DEMO

T4 Video 9/14

Page 10: CUSTOMIZING YOUR SHELLdirk.eddelbuettel.com/papers/t4_003_shell_customisation.pdf · SHELL TIP 3: SOME TIPS AT THE PROMPT How • Briefly: • Applicationscantellbashabouttheircommands

NEXT WEEK

Likely Start with byobu• “Shell session multplexing” made popular by GNU screen• Later replaced / supplanted by tmux• And byobu wraps both with nicer UI and options• Likely Next Sunday

T4 Video 10/14

Page 11: CUSTOMIZING YOUR SHELLdirk.eddelbuettel.com/papers/t4_003_shell_customisation.pdf · SHELL TIP 3: SOME TIPS AT THE PROMPT How • Briefly: • Applicationscantellbashabouttheircommands

SERIES RESOURCE

Source: https://github.com/eddelbuettel/t4

T4 Video 11/14

Page 12: CUSTOMIZING YOUR SHELLdirk.eddelbuettel.com/papers/t4_003_shell_customisation.pdf · SHELL TIP 3: SOME TIPS AT THE PROMPT How • Briefly: • Applicationscantellbashabouttheircommands

ALSO UPCOMING

Source: Blog post at http://dirk.eddelbuettel.com/blog/2020/05/07#rcpp_announce_talk_20200605

T4 Video 12/14

Page 13: CUSTOMIZING YOUR SHELLdirk.eddelbuettel.com/papers/t4_003_shell_customisation.pdf · SHELL TIP 3: SOME TIPS AT THE PROMPT How • Briefly: • Applicationscantellbashabouttheircommands

ALSO UPCOMING

Source: https://chicago2020.satRdays.org

T4 Video 13/14

Page 14: CUSTOMIZING YOUR SHELLdirk.eddelbuettel.com/papers/t4_003_shell_customisation.pdf · SHELL TIP 3: SOME TIPS AT THE PROMPT How • Briefly: • Applicationscantellbashabouttheircommands

THANK YOU!

slides http://dirk.eddelbuettel.com/presentations/

web http://dirk.eddelbuettel.com/

mail [email protected]

github @eddelbuettel

twitter @eddelbuettel

repo https://github.com/eddelbuettel/t4

T4 Video 14/14