Graphviz and ascii output - ascii

Is it possible to draw ASCII diagram using Graphviz?
Something like that:
digraph
{
this -> is
this -> a
a -> test
}
Gives undesired result.
Instead, I would like to get similar ASCII representation:
this
/ \
is a
|
test
How to draw ascii diagrams from dot-files format?

If you are not perl averse, graph-easy (and the associated Graph::Easy package) can do exactly that:
http://search.cpan.org/~tels/Graph-Easy/
http://search.cpan.org/~tels/Graph-Easy/bin/graph-easy
On Mac you can install this with Homebrew and cpan:
brew install cpanminus
cpan Graph::Easy
It's easy to invoke after installation:
cat dotfile.dot | /opt/local/libexec/perl5.12/sitebin/graph-easy

Here is equivalent commands for linux:
First install cpanminus
sudo apt install cpanminus
After you can install GraphEasy
sudo cpanm Graph::Easy
Here is a sample usage
cat input.dot | graph-easy --from=dot --as_ascii

By now, in ubuntu, you can install and use graph-easy directly:
> sudo apt install libgraph-easy-perl
[...]
> graph-easy dotfile.dot
+----+ +------+
| is | <-- | this |
+----+ +------+
|
|
v
+------+
| a |
+------+
|
|
v
+------+
| test |
+------+

Another option to use Graph::Easy's ASCII functionality is directly from your browser through this small service that I hosted:
https://dot-to-ascii.ggerganov.com

Using graph-easy via docker. You can install whalebrew and use it to run graph-easy without installing too much dependancies on your local machine other than whalebrew and docker.
on MacOS with homebrew install docker
$ brew install docker
$ docker -v # check if docker is running
Install whalebrew - https://github.com/whalebrew/whalebrew (check installation alternatives)
$ brew install whalebrew
Install graph-easy via whalebrew
$ whalebrew install tsub/graph-easy
Now run it via
$ echo '[a]->[b]' | graph-easy
+---+ +---+
| a | --> | b |
+---+ +---+

Related

how to use grep with logical operator AND

when searching for packages, i'm using grep, if not installed, i have to install it using shell script as mentioned below:
if
list packages installed | grep rap | grep rap-devel
## only if both are installed then exit with status 0
else
install the missing packages
How should I do this?
I tried this but its very lengthy
yum installed packages | grep rap
if $? = 1
yum install rap
yum installed packages | grep rap-devel
if $? = 1
yum install rap-devel
And I dont think its a good practice to do like this. Can anyone help me to shorten this? what if there still more to search and install 🥲
use && and || operate:
(yum installed packages | grep rap || yum install rap) && (yum installed packages | grep rap-devel || yum install rap-devel)
for more search packages in the list:
pack_list=(rap rap-devel)
for i in "${pack_list[#]}"; do yum installed packages | grep rap || yum install rap; done
or if it could, you could use which rap instead of yum installed packages | grep rap.

How to use local jdk in SDKMAN! script

My script changes to a jdk installed with sdkman but not to a local one. How can I change into my local oracle 8 v261 jdk in a script with sdkman?
The script
#!/bin/bash
. /usr/local/sdkman/bin/sdkman-init.sh
sdk ls java
for i in {"8_261-oracle", "9.0.4-open"}
do
sdk u java $i
done
gives as output
[...]
| | 9.0.4 | open | installed | 9.0.4-open
| >>> | 8.0.265 | open | installed | 8.0.265-open
| | 8.0.232 | open | local only | 8.0.232-open
[...]
Unclassified | | 8_261 | none | local only | 8_261-oracle
================================================================================
Use the Identifier for installation:
$ sdk install java 11.0.3.hs-adpt
================================================================================
Stop! java 8_261-oracle, is not installed.
Using java version 9.0.4-open in this shell.
I was inspired by How to use SDKMAN! to install packages from within scripts.
You could parse the output of sdkman to retrieve the list of installed sdks as follows:
#!/bin/bash
sdks=`sdk list java | grep installed | awk -F"|" '{print $6}'`
for sdk in ${sdks[#]}; do
sdk use java $sdk
### YOUR CODE HERE
done
I have omitted the . /usr/local/sdkman/bin/sdkman-init.sh part because I suggest to set it up in bashrc/zshrc as suggested in sdkman doc.
An example from my ~/.zshrc:
#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
export SDKMAN_DIR="$YOUR_PATH/.sdkman"
[[ -s "$YOUR_PATH/.sdkman/bin/sdkman-init.sh" ]] && source "$YOUR_PATH/.sdkman/bin/sdkman-init.sh"

Automatically update outdated pip3 packages with bash scripts

I have a bash script to automatically update pip3 packages:
It is one line script:
pip3 list --outdated | cut -d' ' -f1 | xargs pip3 install --upgrade
and it has always worked.
Now (maybe after the upgrade to Ubuntu 18.04) it is not working anymore apparently because of a wrong usage of pip3 install.
What is wrong with the script?
Looks like headers of the pip3 list are causing failure in installation of package.
You can trim those header lines by using tail.
pip3 list --outdated | cut -d' ' -f1 | tail -n+3 | xargs pip3 install --upgrade
tail -n+3 removes the header and boundary line which only gives package names to xargs.

remove multiple rpm packages using one bash command

I'd like to use a single bash command to uninstall several packages.
# rpm -qa | grep php
php-common-5.4.16-45.el7.x86_64
php-5.4.16-45.el7.x86_64
php-mysql-5.4.16-45.el7.x86_64
php-pdo-5.4.16-45.el7.x86_64
php-cli-5.4.16-45.el7.x86_64
will give me an output of all the pakcages I'd like to remove, however, how can I pipe that into a remove package command? Something like this:
# rpm -qa | grep php | yum remove ${package}
I tried this and it worked.
rpm -qa | grep php | while read -r line; do yum remove -y $line; done

tree command on osx bash

I'm following a screen cast on a ruby gem called pry. At 8:10, the .tree command is used, which I believe is a Unix command.
It does not appear to be working on my system:
[24] pry(main)> .tree
\Error: there was a problem executing system command: tree
and I have traced the issue to here, in which pry references a shell command:
Pry::CommandSet.new do
command(/\.(.*)/, "All text following a '.' is forwarded to the shell.", :listing => ".<shell command>") do |cmd|
if cmd =~ /^cd\s+(.+)/i
dest = $1
begin
Dir.chdir File.expand_path(dest)
rescue Errno::ENOENT
output.puts "No such directory: #{dest}"
end
else
if !system(cmd)
output.puts "Error: there was a problem executing system command: #{cmd}"
end
end
end
from the context of bash I tried using the command tree with no luck:
projects/sms(apps2)$ tree
-bash: tree: command not found
~/projects/sms(apps2)$ .tree
-bash: .tree: command not found
This looks incredibly useful, how can I get this command?
Using homebrew:
brew install tree
Using macports:
sudo port install tree
Using the source:
Follow these directions. (Caveat; you should use the flags/etc. that make sense.)
<rant>All systems should come with tree; I use it a lot. And we can post directory structures as text, not pics.</rant>
For a simple approach you can also add the following alias to your ~/.bashrc or ~/.zshrc file:
alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"
This results in the following:
$ tree
.
|____.git
| |____config
| |____objects
| | |____pack
| | |____info
| |____HEAD
| |____info
| | |____exclude
| |____description
| |____hooks
| | |____commit-msg.sample
| | |____pre-rebase.sample
| | |____pre-commit.sample
| | |____applypatch-msg.sample
| | |____pre-receive.sample
| | |____prepare-commit-msg.sample
| | |____post-update.sample
| | |____pre-applypatch.sample
| | |____pre-push.sample
| | |____update.sample
| |____refs
| | |____heads
| | |____tags
Found this solution here:
http://osxdaily.com/2016/09/09/view-folder-tree-terminal-mac-os-tree-equivalent/
Use brew install tree command on the terminal if you're using Homebrew on your Mac.
Not exactly the same, but gives you a list of all directories and files in those directories using:
find .
You can also specify list directories only
find -type d
or if you want to see files only
find -type f
you can also specify depth
find -type d -maxdepth 2
Add this to your shell startup file(~/.bashrc or ~/.zshrc):
tree() {
find $1 -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
}
After restarting your shell, you can use the tree command like so:
% tree Downloads
Downloads
|____ideaIU-2020.1.3-no-jbr.tar.gz
|____Firicico.ttf

Resources