Coder Social home page Coder Social logo

cle's Introduction

Command Live Environment

Enhanced shell experience

CLE is a resource that can be loaded upon interactive shell startup. It makes regular work with command line easier by adding fancy features named below:

  • a colorized and customizable prompt string including server time and exit code with highlighting
  • it allows you to save/edit and reuse aliases in an easy way
  • rich history with timestamps, return codes and additional information
  • seamless transfer of the environment and settings to remote sessions
  • configuration right from the commandline with immediate effect, no restarts
  • quick acess to documentation
  • open framework for customization with tweaks and modules
  • install once on your workstation, use everywhere you log in

CLE is compatible with bash and zsh, one resource file for both shells.

1. CLE setup and basic usage

All the mentioned functionality is encoded into single file and no other executables are needed. Download and run this file by sourcing into the current shell context using a trailing dot:

`wget http://git.io/clerc`
`. clerc`
  • Note: you can alternatively download with curl from real source:

    curl -O https://raw.githubusercontent.com/micharbet/CLE/master/clerc

    This is necessary on OSX as there's no wget in default installation. The http://git.io/clerc is only redirecting shortcut.

Now The CLE is activated and you can configure this environment to be persistent with the command:

`cle deploy`

CLE copies itself to $HOME/.cle-YOURLOGIN/rc and adds two lines into .bashrc ev. .zshrc if you run Z-shell. Then it will be started upon each login. Note, this is the one and only installation step you need to perform. Typically you'll only install this on your workstation's account. Do not deploy CLE as root! It would work, and no harm is expected, however it's not recommended. In case you insist on using the root account as your working account, please read the document 'TipsAndTweaks.md' and find the corresponding section.

lssh utility (ssh wrapper)

The CLE is able to pass itself over ssh to a remote system. Use the wrapper called lssh instead of the regular 'ssh' command for a login into a remote account and CLE will be copied over then started seamlessly:

lsu, lsudo, lksu utilities (su/sudo/ksu wrappers)

Those wrappers serve the same purpose as the original su, sudo and ksu utilities, however they add CLE to the sessions.

lscreen - GNU screen wrapper

This wrapper is a workaround to the original GNU screen to allow using CLE inside a screen session. By default lscreen searches for yours opened and/or detached session and jumps into it if found. Otherwise it creates a new screen. Another added value is a configuration file with a nice status line and shortcuts such as Ctrl-Left/Right to switch between windows.

Other utilities

  • aa improved alias management
  • h add colors to regular history output
  • hh rich history, find more information and search by various criteria
  • cle command and control center of the environment.

Find more helpful information directly from command line:

  • cle help to show all commands defined byt he environment
  • cle doc to download and display documentation files

2. Compatibility

CLE has been tested on various systems containing bash version 3.x 4.x and zsh. It works with different flavors of basic utilities (GNU vs. BSD). Strict attention was paid to highly multiplattform compatibility.

Tested systems include the following:

  • Linux Mint
  • Fedora 23+
  • Arch Linux
  • RHEL 5 (bash v3!)
  • RHEL 6
  • RHEL 7
  • CentOS
  • NetBSD
  • FreeBSD
  • OS X (bash v3!)
  • Android (some terminal software requires different tweaks, WIP)

It also works well with at least the following terminal emulators:

  • Terminator, Gnome Terminal, other VTE based teriminals
  • Xfce Terminal
  • xterm
  • rxvt
  • screen
  • Linux console (limited color palette)

3. Requirements

Generally a basic OS installation should be sufficient. Some systems, however, might require you to add missing utilities. Truly necessary utilities are:

  • bash or zsh
  • sed
  • awk
  • base64
  • curl
  • ssh (note, no scp required, e.g no openssh-clients on RHEL)
  • GNU screen (only if you want to use 'lscreen' wrapper)

4. Why 'CLE' and bit of history

My shell environment has been developed over the years of work with command line, where I always tried to have an easily distinguished prompt. It was possible in diferent ways. Basically, I have been editing the shell resource files .bashrc, .kshrc and manually transferring them to each new server and account. Those files may still exist on some old boxes and in scattered backup files. You all probably have something similar.

CLE itself begun as customized .bash resource file itself and a set of utilities. This version worked without 'lssh', instead required installation prior first use on remote account or update if anything changed. The setup was simplified with the 'cle' script but the installation was still a necessary step. Also, .bashrc changes might be unwelcome to other administrators. However this was first, primitive 'life' in command line.

Evolution continues. I removed the setup necessity in an ingenious way - by passing the resource file compressed and base64 encoded through a shell variable to the remote system. To be honest, I was inspired by the 'sshrc' project. Result: no setup, no tweaks on the remote site no harm to the current environment and consistent environment over all sessions!

The only thing you need is a working CLE on your workstation from where you can manage the world :-) Everywhere you go you can now use the same customizable environment! Use lssh instead of ssh or lsu instead of su - root or lsudo' in place of sudo bash`. Those are live wrappers that initiate CLE sessions. In biology terms, the environment can spread own DNA giving the word 'live' it's true meaning. Or at least closer. [1]

CLE versions have no numbers but rather names. As of 2016 following releases were issued:

  • Spring, Easter, MayDay - 2016, very old versions
  • HAlpha - 2017, code cleanup and high optimization
  • RedH - 2017, adding new features
  • Nova - 2018, big improvements, new features again, like rich history
  • Zodiac - 2019, current release, basically the same functions as Nova but almost complete rewrite to ensure compatibility with Z-shell plus improved environment transfer incl. prompt settings, aliases and variables.

Also while CLE is big tweak itself, it tries to respect users and their own settings. Initial versions used to be pushy, defining a lot of aliases, of course those I liked. Wrong! I learned people use their own so I removed them. Shell history as well. There's rich history and tweaks to the regular one have been minimalized. The motto is: "Less tweaks, more options!"

[1] CLE is not a virus :-) It doesn't run itself on any host. Everything is under the users' (your) control and responsibilty

5. LICENSE

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

Find complete text in the file LICENSE.md or at the following URL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html

cle's People

Contributors

josephlemmons avatar limmones avatar mdujava avatar micharbet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

cle's Issues

Add full hostname to prompt

Hello Michal,

thanks for nice presentation yesterday at OpenAlt. Consider this as a wishlist item:

Even during the presentation I asked about showing full hostname (FQDN) on the prompt. There is obvious solution to use standard bash "\H", but it is not working every time. At least in debian, it just shows whatever you have set in /etc/hostname, and that is by default only the first part of the hostname. All the rest is usually in /etc/resolv.conf as domain or search option. So what I really would appreciate is an option to put %H in prompt which would equal to hostname -f.

The reason is that I maintain servers for different companies, and the names tend to repeat (mail.company.com, samba, hyperX, gate, ...) so I need to see the full name.

So far I have to edit /etc/hostname to contain FQDN, and change \h to \H in PS1 definition in bashrc.

Best Regards
Vladki

Regular shell history doesn't show other's admins entries

There was a split in history files. While other administrators on the server were using default history file (.bash_history) the ones using CLE had their personal settings one and used $CLE_D/history-bash. The issue has been reported with strong need to use history or h commands to see all previous commands from all users, regardless if they use CLE or not.

Analysis: Personalization of history file has been one of the first tweaks in CLE.It was useful that time. On the other side there is rich history that was introduced in later release (Nova) and it's ability is also to show only particular user's entries while filtering out the rest.

Proposal: Stop meesing up with the default history settings (not only the file) leaving it all on user.

[Feature request] Shared aliases

Idea:
CLE will manage some config file with aliases (let's say cle sa ll="ls -la") and those aliases will be available on all sessions initiated from cle.

Warn on cle deploy when .bash_prompt is active

Hi,

firstly, thanks for a great tool!

I am trying to use in on the HypriotOS, but strugged to get it working before I relalized that the OS itself comes with a custom ~/.bash_prompt, which sets the prompt colors. After the removal (rename) of the ~/.bash_prompt the CLE works great, it just took me some time to figure out the issue.

My environment:
$ uname -a
Linux proxy 4.14.34-hypriotos-v7+ #1 SMP Sun Apr 22 14:57:31 UTC 2018 armv7l GNU/Linux

How to induce the problem.

  1. login to an environment, where ~/.bash_prompt is created and called from ~/.profile
  2. wget -O /tmp/clerc http://git.io/clerc
  3. . /tmp/clerc
  4. cle deploy
  5. confirm the deployment with y

Output:

  • the command prompt is not changed even after re-login

Expected behaviour:

  • The cle deploy command warns the user that there is .bash_prompt which might collide with CLE.

Thank you,

Martin

conflict with .bash_aliases

Some systems have this code in .bashrc by default:

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

The problem is if there are aliases defined which happen to have the same names as functions defined by CLE. Although there is unalias aa h hh .. ... at the beginning of CLE/rc, it runs ~/.bashrc later and thus all stuff from .bash_aliases is created.

IMHO the unalias ... should be called after sourcing ~/.bashrc (or any external file that could introduce any aliases), or even better, call unalias before defining any internal function. (And best would be to print a warning if an alias was really removed, so the user knows that his good old alias was overriden by CLE).

Exaples I found so far are .. ... (with the same meaning as in CLE) and vdump = virsh dump

ls /nonexistend_dir doesn't return proper error code

Looks like CLE doesn't return proper error code when using ls command:

[0] pruzicka@peru /tmp:$ ls /nonexistent_dir
ls: cannot access '/nonexistent_dir': No such file or directory
[0] pruzicka@peru /tmp:$ ls /nonexistent_dir; echo $?
ls: cannot access '/nonexistent_dir': No such file or directory
2
[0] pruzicka@peru /tmp:$

Thanks for looking at it...

psg from mod-fsps does not work

psg whatever fails - no output, return value 1:

Maybe just missing parentheses:


[0] 00:13 vladki hex ~/.cle-vladki: $ ps -ef | grep bash | grep -v grep
vladki    2336  2327  0 lis07 pts/0    00:00:00 /bin/bash
vladki    2683  2327  0 lis07 pts/1    00:00:01 /bin/bash
vladki    5736  2327  0 lis07 pts/2    00:00:01 /bin/bash
vladki    6455  2327  0 lis07 pts/3    00:00:00 /bin/bash
[0] 00:13 vladki hex ~/.cle-vladki: $ psg bash
[1] 00:14 vladki hex ~/.cle-vladki: $ [ bash ]
[0] 00:14 vladki hex ~/.cle-vladki: $ [ bash ] || cle help
[0] 00:14 vladki hex ~/.cle-vladki: $ [ bash ] || cle help && false
[1] 00:14 vladki hex ~/.cle-vladki: $ psg
 psg name   -- ps | grep
[1] 00:15 vladki hex ~/.cle-vladki: $ 
[1] 00:17 vladki hex ~/.cle-vladki: $ [ bash ] || ( cle help && false )
[0] 00:17 vladki hex ~/.cle-vladki: $ 

rich history removes semicolon from commands on some systems

e.g on RHEL and Centos following has been observed:
issued command:
tail $CLE_HIST | { IFS=';'; while read -r DT SID SEC EC D C; do echo $C; done; }
rich history output:
tail $CLE_HIST | { IFS=' ' while read DT SID SEC EC D C do echo $C done }

This doesn't happen on fedora nor debian

keep the current shell after lsu/lsudo

Hello Michal,

I have access to a server where the "root" prefers /bin/zsh, and has it in /etc/passwd, while I prefer /bin/bash.

With the old version, when I did lsudo, I had still bash. But with the new version I get zsh and this error:

$ lsudo
[sudo] password for vladki: 
[.zshrc]
/var/tmp/root/.zshrc:727: no match

And a zsh prompt, not affected by CLE. /var/tmp/root/.zshrc is symlink to /var/tmp/vladki/.cle-vladki/rc-xxxx

misbehaving prompt composition in live sessions

The prompt composition in live sessions is either not working properly, it might tthow an error abou non existing file or permission error. Or in other case - using lsu/lsudo on worstation, commands cle color and cle pX change configuration of original user.

/var/tmp mounted noexec

Hello,

I often set /var to be mounted noexec for security reasons.
Is there a way to set the old behavior of using ~/.cle-user/ instead of /var/tmp/user/.cle-user/ ?

Now I get:
$ lssh server
bash: line 4: /var/tmp/xxxx/.cle-xxxx/yyyy: Permission denied
bash: line 4: exec: /var/tmp/xxxx/.cle-xxxx/yyyy: cannot execute: Permission denied
Connection to server closed.

Allow different configs cf-HOSTNAME

We have a few servers that share the /home partition via NFS.
In that case it is useful to have different config (colors) for each server.
Default is ~/.cle-username/cf
Server specific version is ~/.cle-user/cf-hostname
It has to be created manually.
This tweak does it:
[[ -r $CLE_D/cf-$CLE_SHN ]] && CLE_CF=$CLE_D/cf-$CLE_SHN

PIPESTATUS

Can you add some info about PIPESTATUS to rich history?

like
hody@x230:/tmp:true | false | true | false
hody@x230:/tmp:echo ${PIPESTATUS[@]}
0 1 0 1

Received bash auto-completion error when logging on as a user

Every time when I use lssh to login to a server, after logging in, I receive the following error message:

bash: /usr/share/bash-completion/bash_completion: No such file or directory

This has been only on Red Hat internal systems as none of my personal systems are affected by this error message.

Error on startup on Mac OS

When starting new instance of cle on the new version on Mac OS, this error happens:

readlink: illegal option -- f
usage: readlink [-n] [file ...]

clerc complains about bash-completion package

It would be nice if CLE detects the missing required packages or ask permission to install them.

[savitoj@savitoj-test ~]$ . clerc
-bash: /usr/share/bash-completion/bash_completion: No such file or directory
 It seems you started CLE running '/home/savitoj/.cle-savitoj/rc1' from command line
 Since this is the first run, consider setup in your profile.

cc: @micharbet

"Alias" 'cle -h' and 'cle --help' to cle help

Here is an idea. Add options -h and --help to cle command, so that people don't have to remember that for help they need 'cle help' exactly. The option -h doesn't seem to be taken by anything else.

cle color set not remembered (set to an empty string)

When I tried to set a color for the prompt, it worked fine until I logged out.
When i logged back in, the CLE complained about non-existent color.

# cle color yellow
[0] 15:34 root xray136 ~ #
--- logged out ---

after logging in:

Unknown color '' Select one of predefined:

Chování v rámci shellu v Midnight Commanderu

If there is mc started in CLE, and any command in it - there is an error (even if command is processed correctly):

[0] 12:56:31 msiebenb  ~ $ date
St 14. října 2020, 12:56:32 CEST
bash: [: příliš mnoho argumentů
[0] 12:56:32 msiebenb  ~ $ 

Milan Siebenbürger

Best way to override lssh

Hey there, where would be the best place to override the lssh function? I would like to use mosh instead of ssh but also to be able to update cle and keep it "viral" :-)
Thank you!

CLE_Px incompatible change in new version

Hello, after long time I tried to update CLE, and found out that my prompt is all wrong.
After several "cle cf reset" and "cle cf revert" and login/logout I ended up with the defaults, which are at least useable.
But the problem is that I have my tweaked prompt in cf-hostname, all around on many servers an this is getting very very broken. I see that you moved from %x to ^x notation. Is it possible to get some backwards compatibility with the old prompt notation?

CLE doesn't display /etc/motd

Message of the day should be displayed upon remote login. Some might find important information in it. reported by: @vhodina

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.