Code Monkey home page Code Monkey logo

synth-shell's Introduction

synth-shell

synth-shell improves your terminal experience and productivity by adding color, extra info, and convenience. It is not a single tool, but a collection of scripts and aliases (feel free to install only those you want) all written in bash. See the overview section for a detailed list and options.



Quick setup

This section covers the vary basics if you want to get started as fast as possible. See the setup section of this file for more details. Also, before you get started, and to get the best possible experience there are important considerations:

  • power-line fonts: install package powerline-fonts on Arch or fonts-powerline on Ubuntu.

  • terminal font: configure your terminal emulator to use a nice font. We recommend hack-ttf which you can install for most distros under that name.

  • Remember that support for Windows is not guaranteed. But feel free to fix any bug you encounter and contribute to this project.

  • Clone this repository recursively since there are git submodules in it (you only have to copy pase the commands down below as they are).

Once everything is ready, it is as easy as copy-pasting the following commands to run the included setup script.

git clone --recursive https://github.com/andresgongora/synth-shell.git
cd synth-shell
./setup.sh

When prompted, select install (default) and user (default). Afterwards, you might need to open a new terminal. Afterwards, you can customize everything to your liking.



Overview

The following tools and scripts are included in the synth-shell package:

  • System status report (aka synth-shell-greeter):

    • Shows for every new terminal session (local, SSH, ...).
    • Monitor your servers, RaspberryPis, and workstations. All system info you need at a glance (e.g. external IP address, CPU temperature, etc.).
    • Detect broken services or CPU hogs by printing extra diagnostic data, but only when needed.
    • Print your own ASCII logo every time you log in or, if none specified, your distro's logo.
  • Fancy bash prompt (aka synth-shell-prompt):

    • Configurable colors and aesthetics.
    • Git statuses (requires pull/push, is dirty, etc.) if inside a directory that is part of a git repository.
    • Better separation between user input and command outputs.
  • better ls: an ls -la on steroids alternative.

  • alias: add colors and a nicer behaviour to basic commands.

    • grep.
    • pacman.
    • tree.
    • dmesg.
    • free.
    • sudo: autocomplete commands.
    • history: nicer format and no duplicate (consecutively the same) commands.

Example with status.sh and fancy-bash-prompt.sh

All features are optional, and most can also be customized to your liking. Once installed, the scripts are called from within you .bashrc file and become part of the bash session. Everything is written in bash and should work out of the box on almost any Linux system (you might need to install some dependencies, but that is all).

status.sh

status.sh provides a summarized system report at a single glance every time you open up a new terminal. If it detects that any system parameter (e.g. CPU load, memory, etc.) is over a critical threshold, it will provide a warning and additional information about the cause. Last but not least, it prints a user-configurable ASCII logo to impress your crush from the library with how awesome you are.

Feel free to customize your status report through the many available options in ~/.config/synth-shell/status.config (user-only install) or /etc/synth-shell/status.config (system-wide install),or by replacing their content with the examples files you can find under the same directory.

status configuration options

fancy-bash-prompt.sh

Adds colors and triangular separators to your bash prompt, and if the current working directory is part of a git repository, also git statuses and branches. For best results, consider installing (and telling your terminal to use) the hack-ttf font alongside the powerline-fonts (the later is required for the separators).

As for the git status info, fancy-bash-prompt.sh prints an additional, fourth separator with the name of the current branch and one of the following icons to indicate the state of the repository (can be changed in the config file):

Local-Upstream Local branch has no changes Local branch is dirty
Up to date !
Ahead (you have to push)
Behind (you have to pull)
Diverged (you have to pull-push)

better-ls.sh

Makes ls print more text, but nicely formatted. When called, ls will now list all files (-la), sort folders first, add colors to output, and list hidden files last after a quick separator. However, if you chose to call ls with your own parameters (e.g. ls -l) it will revert to the default behavior except for color and sorting options.

Alias

  • grep to grep --color=auto.
  • pacman to pacman --color=auto.
  • tree to tree --dirsfirst -C.
  • dmesg to dmesg --color=auto --reltime --human --nopager --decode.
  • free to free -mht.
  • sudo adds complete -cf sudo to auto-complete commands.
  • history various changes.



Setup

Automatic setup

The included setup script will guide you step by step through the process and let you choose what features to install. During this setup, you can choose to install synth-shell for your user only (recommended) or system-wide (superuser privileges required). To proceed, open and play this link in a separate tab and enter the following into your terminal:

git clone --recursive https://github.com/andresgongora/synth-shell.git
chmod +x synth-shell/setup.sh
cd synth-shell
./setup.sh

Note that for fancy-bash-prompt.sh you might also need power-line fonts. You can instal it as follows (the exact name of the package varies from distro to distro):

  • ArchLinux: sudo pacman -S powerline-fonts
  • Debian/Ubuntu: sudo apt install fonts-powerline

Finally, open up a new terminal and test that everything works. Sometimes, despite power-line fonts being properly installed, the triangle separator for fancy-bash-prompt.sh (if installed) might still not show. In this case, make sure that your locale is set to UTF-8 by editing /etc/locale.conf file (select your language but in UTF-8 format) and running sudo locale-gen. More info on locale. Alternatively, try a different font in your terminal emulator. Some fonts do not support special characters. We get the best results with hack-ttf.

Configuration/customization

You can configure your scripts by modifying the corresponding configuration files. You can find them, along the example configuration files, in the following folders depending on how you installed synth-shell:

  • Current-user only: ~/.config/synth-shell/
  • System wide: /etc/synth-shell/

Uninstallation

  1. Edit ~/.bashrc and remove the lines referring to synth-shell, usually at the bottom of the file. If you want to temporarily disable the script, you can just comment them by placing # in front.
nano ~/.bashrc
  1. Remove the folder containing the script, usually in your home folder under ~/.config/synth-shell/.
rm -r ~/.config/synth-shell/



Contribute

This project is only possible thanks to the effort and passion of many, including developers, testers, and of course, our beloved coffee machine. You can find a detailed list of everyone involved in the development in AUTHORS.md. Thanks to all of you!

If you like this project and want to contribute, you are most welcome to do so.

Help us improve

  • Report a bug: if you notice that something isn't working properly, tell us. We'll try to fix it ASAP.
  • Suggest an idea you would like to see in the next release: send us and email or open an issue!
  • Become a developer: fork this repo and become an active developer! Take a look at the issues for suggestions of where to start. Also, take a look at our coding style.
  • Spread the word: telling your friends is the fastest way to get this code to the people who might enjoy it!

Git branches

There are two branches in this repository:

  • master: this is the main branch, and thus contains fully functional scripts. When you want to use the scripts as a user, this is the branch you want to clone or download.
  • develop: this branch contains all the new features and most recent contributions. It is always stable, in the sense that you can use it without major inconveniences. However, it's very prone to have undetected bugs and it might be subject to major unannounced changes. If you want to contribute, this is the branch you should pull-request to.



About

synth-shell started as a loose collection of (very simple) bash scripts I used for system maintenance. In the beginning, they were simple aids to make my life easier, but as I progressively got the hang out of bash, I also wanted them to print some nice output to the terminal.

This repository was quite different at the beginning. The content of most scripts were loose snippets from third parties that were somehow smashed together. They worked, but not exactly the way I wanted. So, over time I have rewritten most scripts from scratch, removed fluff, and teamed up with super-friendly and engaged contributors. The result is what you see today. I admit it, it's nothing fancy. But it was real fun working on the scripts.

And the name? That's quite easy. I spent most of my coding frenzy listening to SynthWave to feel like Hackerman.



License

Copyright (c) 2014-2021, Andres Gongora - www.andresgongora.com

synth-shell's People

Contributors

andresgongora avatar emberavenge avatar isanych avatar mcgillij avatar olmari avatar peterjriches avatar sambwest avatar sandropernerstorfer avatar valeriomagnago 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  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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

synth-shell's Issues

Script to read configuration files

Most scripts have some sort of internal configuration section, mostly for color schemes and such. It should be possible to optionally allow the user to extract said configuration to an external file (i.e. inside ~/.config) such that the script remains the same for all deployments, but may be configured as needed between different machines (i.e. different color schemes depending on the host).

Thus, I need a config reading script that, when invoked from an external scipt can either:

  1. Read some configuration from an external config file and return the value of specific KEYWORDS
  2. Read the configuration within the very same external script (i.e. if no config file is specified, use the external script as such)

Thus, sse a mechanism like $var = config_get KEYWORD OPTIONAL_CONFIG_FILE; where it searches in the optional file (if non specified, use current file) and returns the value of said keyword.

Add optional messages to status through a menu

Add a menu script that allows me to run some extra diagnostics, or by default (hitting enter), go into a simple terminal. Said options could include stuff like:

  • journalctl -p 3 -xb
  • netstat -atp #add -n to show IPs instead of host names
  • find -xtype l -print # Find broken symlinks
  • dmesg
  • -TP --level=err,crit,alert,emerg

More ideas:

Coding style guide

Create a small text file with basic coding style guides for this project - mostly a reference for myself to be more constant and uniform between scripts, but also as a guide for new developers who might want to join this project.

The goal is not to come up with a complete guide, but to start small and gradually add more content as we see fit.

  • Variable names
  • Function names

Consider making this into two separate repos

  1. Repo with all other scripts (which noone uses but me xD) and the common scripts.
  2. Repo with status, fancy-bash-prompt installer, config examples. Include first repo as submodule.

@olmari you have more experience. Would it be a good idea? I mean, this way our work could become a "bunch of script" solely aimed at improving the terminal experience; instead of a collection of loose scripts. Also, the installer only installs status and fancy anyway...

Problem is. Can I rename this repo?

Avoid variable name leakage

Most scripts don't clean up after them self and leave lots of variables inside the user's session. Fix this with local variables or unsetting variables that are no longer used.

Beautify install script

  • Use common.* script to print and prompt with beautiful texts and colors
  • If no argument provided, run in default mode (for example, if called from an AUR package)
  • Options to choose what to install
  • In manual mode: Print a header with information of what is going to happen. After installing each script, tell the user what files where modified (request by Duarte)

Limit CPU % to 100 and make it a bit faster

Currently, the CPU percentage is shown as the average of the last minute. This is meant to avoid showing the spike of loading up a terminal and such. I suggest the following changes:

  • Get CPU usage % as the average of the last 10 or so seconds. Ideally, make this user configurable.
  • Compute CPU % in the range [0-100]. Right now, if you have 8 cores, the range would be 0-800.

But beware of breaking CPU_CRIT alarm. With 8 cores, if one of them is at 100% because some program is doing nasty stuff, but the rest is idle, the average load would still seem to be below 13%. This requires to think everything through.

Maybe replace the bar all together with something different?? (it must still fit in a single line)

Get external IP in parallel

This is just an idea, but how about this:

  1. Check what tools the user has to get her external IP
  2. (somehow) call them all in parallel
  3. Use the first one to finish

Run scripts from within bashrc instead of sourcing them

  • Advantage: no user environment contamination with function names and variables

  • Disadvantages: the script must be ensured to be executables. This was not needed because bashrc is an executable and took care of the "permissions" for us.

Now load avg is % again?

Where did the actual load-figure went? :P At least develop branch is now not curent vompared to master :)

Sort scripts and add a summary table to README with info

  1. Sort scripts into sub-folders depending on functionality. For example, separate scripts meant to "improve" the terminal experience from those meant to aid in system maintenance or simple utility scripts.

  2. Allow everyone looking into this repo to recognize what each script does. Add a table with the scripts name and its main utility in 1-2 sentences

Move all configuration files to common location

Right now it's a mess to change the configuration files. The user must really know what she is doing. I think that the configuration files should be in a more logical location.

  • Put configuration files in a better location
  • Explain how to change the configuration in the README. As of now, it does not even say that the scripts can be modified

Fix automatic padding in status.sh

There is an issue for lower MAX_DIGITS values. For instance, if the HDD has 56GB capacity, and 43GB used, it will show as follows:

  • MAX_DIGITS=5 leads to 43/56 GB
  • MAX_DIGITS=4 leads to 4/56 GB - INCORRECT
  • Fix padding
  • Fix for floats as suggested during merge

Create additional, optional, configuration files

To anyone reading this: Feel free to paste here your configuration files. I will add them and cite you as their original author

Planned themes

fancy-bash-prompt.sh

  • red theme
  • green theme
  • orange theme
  • yellow theme
  • gray theme

status.sh

  • MAPIR theme
  • root theme
  • ArchLinux theme
  • Debian theme
  • Ubuntu theme
  • Manjaro theme
  • DISAL

Color script

Most of my scripts rely on colors for aesthetically purposes. Instead of replicating the code in each file, create a single script that takes care of either creating returning color command tags (to be added to a string) or to return "colorized" strings (to be then printed or concatenated).

  • Recognize terminal color compatibility, and adjust properly. If terminal is B&W, then it should apply no colors.

  • Intuitive, verbose and explicit

Status fails if no swap is set

There comes error on screen if there is no swap set up and also Swap status line also fails.

We need to add check if there is any swap set up before we try to show it, I'd suggest showing "N/A"

Status.sh with no swap set up at all

Separate logo drawing and status-lines drawing

  • Separate (smart) logo and info printing
  • Update configuration files with new parameters
  • Make all status-info lines optional (allow user to hide or change their order)
  • Multi line info loading (required for logo)
  • Enable multi-colors in logo (written inside config file)
  • Allow to place the logo on the right instead of the left

Make logo drawing separate function and do that first, then at separate function draw statusdata lines. This way logo is easier to manage, especially if smaller than maximum lines, and then if terminal windows is too small to fit all the status data we can more easily to cut our way into the logo area.

We can use ANSI escape characters to actiave that, more info at https://unix.stackexchange.com/questions/210325/posix-command-that-moves-cursor-to-specific-position-in-terminal-window

This would also take care/include #42

Also here is very simple test in terminal, I made few lines of positioned text, and then on next command I used overlapping position:

A long text in terminal

New text that replaces part of old one

Ways to get current public IP-numbers

After #24 gets done, we need ways to check what programs are there, and then properly use them. I will gather code snippets to here in later comments.

  • Method to determine what programs are available on system.
  • Figure out proper usage of each program.
  • Method to use first found program and ignore rest...
  • ...but try next program if earlier one fails to work

dig command not found

Some commands, like dig, might not be present on the user's system.
Either make them a dependency, or make it such that the script just skips them without breaking. Alternatively, see what commands DO usually exist and use them instead.

Fix better-ls for all distros

ls is not always under /bin/usr/. The script should search for ls under different folders (maybe iteratively?) until it finds the correct executable; then, it should store the path to said executable in a variable and from there on use that variable for the rest of the script.

status.sh - Repack everything into functions

All variables that are displayed should be "provided" by a function with the appropriate name, instead of being stored in variables.

That way, we can easily add extra functionality in a modular and salable fashion. For example, a function called getExternalIP might do several checks to find the best tool to get the IP instead of resorting only to dig or wget (as suggested by @olmari ).

This also helps with #20

Apply modular scripts to currently existing scripts

  • Apply config to status.sh
  • Apply config to color.sh
  • Apply config to alias.sh
  • Apply color.sh to status.sh
  • Apply color.sh and config.sh to fancy-bash-prompt.sh
  • Update main README file with a brief description of the new modular scripts
  • Update README with instructions regarding how to change the configuration to the user's liking
  • Put all config files in a better location - dedidated folder maybe??

status.sh hangs the terminal, gives message "cat: /etc/upstream-release: Is a directory."

The script status.sh doesn't work properly for me. It hangs at the very part of the script, where it is looking for OS information. The command "cat /etc/*-release" works fine by itself though, so I guess something is wrong with how my system is interpreting the bash script. Any advice?
I know I can just ctrl-c and stop it, but I'd like to actually see the script run the way it is supposed to.

Make date format configurable

Currently getSysDate() has hardcoded value of "%Y.%m.%d - %T". This should be also user configurable at config-file.

Show sys load avg value with 2 decimal points

Now the new sys load average that shows "current load" / "available processing units" rounds the "load" number to nearest integer. This isn't too helpful in load context (like it was as percentage figure). Let's change the value from X / Z to X.YY / Z to reflect how "load" value works .

Add installation script

Add installation scripts that take care of copying everything into place, and if possible, an AUR script, for:

  • Better bash promt
  • System-status terminal greeter
  • Prevent multiple additions of the anchor in /etc/bash.bash.rc
  • Automatic installation and manual installation
  • Uninstall
  • Update instructions for installer
  • Update instructions for user-specific config

printTop() fails if $cpu_is_crit is true

When CPU load average goes above determined critical value, status.sh fails to print proper data and/or prints out also printf error:

Output error on CPU above critical

(Logo being improperly aligned is another on-going thing, no need to point that one out)

Error in v1.3 after autoinstall

This error was reported by drqxr

bash: printf: `Y': invalid format character

which: no dig in (/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)
which: no nslookup in (/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)
  • Fix printf Y
  • Fix which
  • Add instruction to README for uninstall

Ass soon as all the fixes are implemented on my PC, I will push them to the github repo.

Search for binaries in common folders

Create a utility script that can be called from the other scripts such that I can adapt the path of the code depending on the distro. For instance, the following code is very common in my scripts. It could be converted to a simple function.

## GET LOCATION OF TREE COMMAND -> Check for all possible locations
if [ -f "/usr/bin/tree" ]; then
	TREE="/usr/bin/tree"
elif [ -f "/bin/tree" ]; then
	TREE="/bin/tree"
else
	echo "tree command not found"
fi
alias tree="$TREE --dirsfirst -C"

Add photo to README to show what the script do at a glance

  • Main photo showing the coolest functionalities
  • Optional extra photos showing other stuff

Right now, when looking at the repo, it's impossible to tell what it does... I probably wouldn't pay much attention to this repo if I stumbled upon it by chance. This must be fixed :P

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.