command live environment · variable purpose cle_user username from first login on cle workstation,...
TRANSCRIPT
CLE 11/20182
AGENDACommand Line Environment
What, Why, for WhoWhat CLE does, What are its purpose and benefits
Living with CLEInstallation, configuration, usage
The magic insidePriciples, variables, tweaks
CLE 11/20184
What CLE provides Colorful prompt!
Distinguish commands and outputs
Have important information visible
Create your own style
Alias management
Define and remember aliases
Edit your alias set
Rich history
More information about your work
Endless and easy to search
Live sessionsSeamless login with the same environment without installation
No harm to default settings
Multi-admin environment Open framework
Options to add custom features
Self documented
All in one compact script
CLE 11/20185
Alternatives
1. Your own .bashrc / .zshrc
You know what is there
Need to edit the file, reloginRequired to be added on each new account
2. 'powerline'
Nice, well known solution
Huge complicated python scripts behind
Running daemon! (for just cmdline...)
Requires installation on destination boxes
3. 'sshrc'
Partially solves seamless transfer
Yes this one inspired me!
CLE 11/20186
Who can benefit from CLE
● Administrators, accessing a lot of servers *
● Support engineers creating reproducers
● Developers
● ...anybody using command line daily
*) more users access the same root account with individual settings!
Why this all?
● Install once, use anywhere
● Easy configuration without reload
● Lazy admin's live becomes more comfortable
CLE 11/20188
Start• Main source: http://raw.githubusercontent.com/micharbet/CLE/master/clerc• Easy going: https://git.io/clerc $ wget http://git.io/clerc
$ . clerc$ cle deploy
Exercise #1: download & run
CLE 11/20189
First aid kit
CLE employs TAB autocompletion
CLE is documented, use following ways to learn more:• Quick help (strings inside the script) cle help or cle -h
• Thorough documentation (download) cle doc
You will never walk alone!
CLE 11/201810
Prompting
[0] 12:15 fool stalker.usersys ~ $ _
CLE_P1Username
‘\u’
CLE_P3Working dierctory
‘\w \$’
CLE_P2Shortened hostname
‘^h’
CLE_P0Return code + time
‘^E \A’
Exercise #2: setup prompt colors
cle colorcle color greencle color RgBcle color CgGY
Use predefined scheme or try your own combinations.
CLE 11/201811
Prompting Exercise #3: setup your prompt stringscle time offcle p1 '\u@^h'cle p2 ' $VARIABLE \n'cle p2 '^cM^vVARIABLE'cle p2 'date $(date)'cle p3 '\w:^g \$'
Pro tips: - use TAB completion to get current parts definitions - find more escape sequences using cle doc
Note: distinguish between bash sequences e.g. ‘\u’ and CLE additions introduced with caret sign e.g. ‘^h’
INSERT DESIGNATOR, IF NEEDED12
Live sessions CLE can pass itself over remote login and su*
Exercise #4: Use lssh instead of ssh
CLEWorkstation
srv1[0] fool ws ~ $ lssh root@srv1 (CLE packs itself, transfers through ssh and runs)[0] me-root srv1 ~ # lssh virtual [0] me-root virtual ~ # _ virtual
INSERT DESIGNATOR, IF NEEDED13
Live sessions CLE can pass itself over remote login and su*
Exercise #5: Use lsu, lsudo or lksu
CLEWorkstation
[0] fool ws ~ $ lssh srv1 (CLE packs itself, transfers through ssh and runs)[0] fool srv1 ~ # lksu [0] me-root srv1 ~ # _
root@srv1
fool@srv1
Note: Regular ‘ssh’ and ‘su*’ commands will behave normally, like if CLE does’t exist
CLE 11/201814
CLE in screenUse command lscreen to start CLE session in GNU screen
Features:• Customized configuration• Automatic rejoin detached screens• Easier screen sharing
Exercise #6: work with lscreen• Open more shells <ctrl-A><ctrl-C>• Do something (e.g. ‘ls’)• Switch windows with <ctrl-Left/Right>• Detach screen session <ctrl-A><ctrl-D>• Start over, just type ‘lscreen’
CLE 11/201815
Work with aliases
aaaa tlg='tail -f /var/log/messages
Exercise #7: use command aa
Open new session, new aliases are there!
aaaa -e (you can edit your aliases!)
Define new alias, watch the alias set
CLE 11/201816
Rich history
2018-08-02 11:02:14 mich-8300 15 2 ~/gam-rh gam add group cpq-development-team
2018-08-02 11:02:30 mich-8300 2 0 ~/gam-rh gam create group cpq-development-team
2018-08-02 11:02:37 mich-8300 2 0 ~/gam-rh gam create group clm-development-team
Timestamp session secs rc dir command
h (known bash colored history)
hh (this is the rich history)
hh 15 (recent 15 entries)
hh gam.*group (use regexp)
Basic history usage using hh
Did you know shell's <Ctrl-R> to interactive search through history?
CLE 11/201817
Rich history Advanced searches
hh -d grep (all today’s greps)
hh -shh -tsc (see only successful commands issued in this terminal)
hh -dsc (guess the difference)
hh -f 500 (folder history within recent 500 commands)
Use ‘cle help hh’ to see all rich history options
Exercise #8: • inspect rich history over multiple sessions• Open live session on the same account and watch history
records of other users
CLE 11/201819
How CLE works
• Resource file lives in separate folder $HOME/.cle-yourname • Hooked into .${CLE_SH}rc (with command cle deploy)• All in one file, including basic documentation• Defines bash functions – to be executed in context of current shell
process• Seamless live sessions use tar and base64 encoding to pass CLE
files to remote hosts• Self-contained documentation uses '##' double-hash to denote
comments worth to print out using 'cle help'
CLE 11/201820
Internal variables
Issue 'cle env' to inspect all variables
Use ‘cle doc’ and chose file HOWTO.md to read more
Variable PurposeCLE_USER Username from first login on CLE workstation, inherited
over all live sessions. Most important variable used to name cle files
CLE_RC Full path to the resource file itselfCLE_TW Relative path to tweak fileCLE_D Directory with working files (configuration and more)CLE_CF Configuration fileCLE_CLR Color scheme, related command ‘cle color’
CLE_Px (x=0..3) Prompt parts definitions, related commands ‘cle p1..p3’
_Cx Color table, e.g. $_Cr contains escape code for red
CLE 11/201821
FilesFile/folder Purpose
$HOME/.cle-$CLE_USER Here is almost all that CLE needs. Other mentioned files are related to this directory ($CLE_D)
… rc Resource file with the environment itself ($CLE_RC)… cf Configuration file ($CLE_CF)… tw Tweak file ($CLE_TW)… aliases Locally defined aliases$HOME/.history-ALL Rich history file$HOME/.history-$CLE_USER User’s personal history (replaces .bash_history)
Inspect file HOWTO.md using ‘cle doc’ to read more
CLE 11/201822
Tweaks and modules
# this is my CLE tweakecho Welcome $CLE_USER as $USER at $(hostname -f)# Yellow error code_Ce=$_CY
Using ‘cle doc’ inspect following files:TipsAndTweaks.md
Modularity.md
• Try not to edit CLE resource file itself. Instead submit bugs or feature requests on Github
• Place following code into your $HOME/.cle-$CLE_USER/tw:
Make it yours!
Use ‘cle mod’ to enhance functionality, e.g.:cle mod add promptcle prompt triliner
# this is my CLE tweakecho Welcome $CLE_USER as $USER at $(hostname -f)# Yellow error code_Ce=$_CY
CLE 11/201823
Go deeper, have fun• Check how things are coded• Close look at use of variable $CLE_USER – how it is created then
inherited over sessions and how it ensures multi-admin environment.• See comments, esp. Self-documentation• Note, it might be sometimes not easy to read, code is quite dense,
heavily using regular expressions, etc...
Exercise #9: find Easter Egg!● It's there!● Uses function 'cle'
Review the script!
Thank you!“Make love, not core dumps!”
The creator: [email protected] project: https://github.com/micharbet/CLE