I need to document a command and its output side-by-side - html

I'm currently developing a set of shell functions and I want to document its output.
I remember there's a command that generates a basic outline in html (and markdown?) where on the first column you've got the command and it output on the right. A crude example:
ls -a1 | .
| ..
| a_dir/
| a_file
| another file
|
ps | PID TTY TIME CMD
| 2920 pts/2 00:00:00 bash
| 3015 pts/2 00:00:00 ps
I would like to know a program that given a set of commands will generate something similar to the previous example, whether it is HTML, markdown, or anything similar.

One way is to use the script utility
SCRIPT(1) User Commands SCRIPT(1)
NAME
script — make typescript of terminal session
SYNOPSIS
script [-a] [-c command] [-e] [-f] [-q] [-t[=file]] [-V] [-h] [file]
DESCRIPTION
script makes a typescript of everything printed on your terminal. It is
useful for students who need a hardcopy record of an interactive session
as proof of an assignment, as the typescript file can be printed out
later with lpr(1).
There is also a python-utility available, called shelllogger
ShellLogger captures all user interactions with a shell. It is intended to be used for software engineering researchers who are interested in inferring programmer behavior from data that can be captured automatically during a programming session. It is similar to the Unix 'script' program, but provides additional features such as XML output, distinguishing user input from system output and tracking the user's current directory.
https://code.google.com/p/shelllogger/

Related

Passing nano a specific filename inside a function

I'm relatively new to shell in general, only recently started learning bash scripting and how to use it in automation. Problem is that I use zsh as my daily shell and would like to get into habit of using command line text editor and specifically nano, at least for now.
To do so (and also to practice making scripts and tweaking configuration files) I tried to make a function within .zshrc which would cd me into a particular directory I use for my Free Writing library, then create a file with today's date as its name and enter interactive nano session.
Code of said function
function ok_go() {
cd ~/Library/Mobile\ Documents/com~apple~CloudDocs/Freewriting
nano $(date %d.%m.%Y)
}
Problem is nano doesn't really get the name, it cd's into the right directory, starts a file editor but the name is blank. But for some reason, if I use nano $(date %d.%m.%Y) interactively (call it myself) it works as I intended, i.e start the edit of the file with a name of something like 21.04.2021.txt
Don't really get why it doesn't work from a function call and how can I make it behave like a want. Thanks!

How do I call an internal Midnight Commander command from menu entries or key bindings?

I try to automate some things for my Midnight Commander setup and want to call an internal Midnight Commander command from menu entries or key bindings.
For example, I have a large number of ssh sites defined in .ssh/config,
# ssh (secure shell) configuration file
Host test1
HostName 123.456.789.0
Port 980
User MyUserName
Host test2
HostName test.mynet.local
User test
CheckHostIP no
..
I want to filter and sort the aliases from .ssh/config (for example with):
grep '^Host ' .ssh/config | cut -d ' ' -f 2 | sort
Store the resulting list in a Midnight Commander internal list box or selection panel.
Select one of the entries and call the remote shell for the right file panel (like mc sh://%s...).
At least I want to store the procedure to a key binding or a Midnight Commander menu entry.
Could this be done with Midnight Commander board tools or configuration files?
What you're trying is impossible as mc is not a scriptable file manager. It doesn't even have keyboard macros.
But I can think of a few weaker alternatives.
Use F2-called menu (see the manpage for format, section "Menu File Edit"). In the menu run your grep command, pass the list of hosts to a program like dialog to select a host and run mc sh://$host. The problems with the approach: you need to learn dialog; there will be a second copy of mc which detects presence of the first and asks if you really wants to run the second. Ouch!
Alternatively write a script that will run the grep command, get the lists of hosts and programmatically edit ~/.cache/mc/history. The file is ini-like file. You need to edit section [inp:fishlink_cmd: Shell link to machine ]. The keys are just consecutive numbers, the values are host names. Example:
[inp:fishlink_cmd: Shell link to machine ]
0=Host1
1=Host2
Now press F9, R[ight], h (for Shell command) — in the opened dialog there will be the list of hosts. Press Alt-p/Alt-n for previous/next host or open the list with mouse.

how to use emacsclient -e "command" to convert a .org file to html?

I want use emacsclient -e "command" to covert org mode file to html file, such as:
emacsclient -e "(org-html-export-as-html ./mynote.org)" > ./mynote.html
hope it will be save output to mynote.html file.
But I'm not familiar with elisp yet. Actually, org-html-export-as-html has many parameter I don't know how to use it.
A/ You can do it "yourself" with:
emacsclient -e "(progn (find-file \"file.org\") (org-html-export-to-html) (kill-buffer))"
Caveat: to make it works you should have started Emacs with
emacs --daemon
or if you already have an Emacs running, type M-x server-start
B/ use a github package
https://github.com/nhoffman/org-export
which creates some compiled lisp executables:
org-export html
org-export tangle
...
However my personnal experience is that the command line approach is faster.
C/ Bonus, tangling file
You can tangle files with the same command line approach:
emacsclient -e "(org-babel-tangle-file \"file.org\")"
Update, gives more details about C/
"tangling" is a term coined from literate programming
Literate programming (LP) tools are used to obtain two representations
from a literate source file: one suitable for further compilation or
execution by a computer, the "tangled" code, and another for viewing
as formatted documentation, which is said to be "woven" from the
literate source.[3] While the first generation of literate programming
tools were computer language-specific, the later ones are
language-agnostic and exist above the programming languages.
You have a unique file:
#+TITLE: My Org file
* Configuration
#+BEGIN_SRC bash :tangle yes :tangle "tangled.sh" :shebang "#!/bin/bash"
echo "This is my configuration script"
echo "..do something interesting here.."
#+END_SRC
You can html export it (parts A/ or B/), but but can also export the code it contains, here a shell script. From Emacs this can be done with C-c C-v t or, from shell, using the command I provided in C/ part. The result is the automatic generation of the tangled.sh file.
You can have a look here: Babel: active code in Org-mode for further details.
IMHO, correct way should be
emacsclient -e "(org-html-publish-to-html '() \"file.org\" \".\")"
But it complains about *ERROR*: ‘org-publish-cache-get’ called, but no cache present - for me it looks like a bug in Org-mode

Configure PHP CodeSniffer to fix code on the fly in PhpStorm

I have PhpStorm 10 and want to setup php Code Sniffer to automatically correct me code. This article https://confluence.jetbrains.com/display/PhpStorm/PHP+Code+Sniffer+in+PhpStorm points to "Project Settings | Code Style" and I cannot even find that. I have File | Edit | View | Navigate | Code | Refactor | Run | Tools | VCS | Window | Help at the top and have no idea where to find project settings. I do have File > Settings but cannot figure it out.
My project is a web portal built in Symfony. I saw a colleague run Atom and when he saves a file it is code-fixed on the fly - that is what I want. Help please.
PhpStorm does not support code fixing on the fly with Code Sniffer.
https://youtrack.jetbrains.com/issue/WI-25815 -- watch this ticket (star/vote/comment) to get notified on any progress.
Right now, if you wish you may create an External Tools entry for that and run it manually when needed.
Find this from web (how to config the external tools)
https://thiagoponte.wordpress.com/2015/08/03/run-php-codesniffer-code-beautifier-and-fixer-from-phpstorm/

Solution to programmatically generate an export script from a directory hierarchy

I often have the following scenario: in order to reproduce a bug for reporting, I create a small sample project, sometimes a maven multi module project. So there may be a hierarchy of directories and it will usually contain a few small text files. Standard procedure would of course be to create a zip file and send that. But on some mailing lists attachments are not allowed, and so I am looking for a way to automatically create an installation script, that I can post to such mailing lists.
Basically I would be happy with a Unix flavor only that creates mkdir statements to create directories and >> statements to write the file contents. (Actually, apart from the relative path delimiters, the windows and unix versions can probably be identical)
Does such a tool exist somewhere? If not, I'll probably write one in java, but I'm happy to accept solutions in all kinds of languages.
(The tool could run under windows or unix, but the target platform for the generated scripts should be either unix or configurable)
I think you're looking for shar, which creates a shell archive (shell script that when run produces a given directory hierarchy). It is available on most systems; you can use GNU sharutils if you don't already have it.
Normal usage for packing up a directory tree would be something like:
shar `find somedirectory -print` > archive.sh
If you're using GNU sharutils, and want to create "vanilla" archives which use only the most portable of shell builtins, mkdir, and sed, then you should invoke it as shar -V. You can remove some more extra baggage from the scripts by using -xQ; -x to remove checks for existing files, and -Q to remove verbose output from the archive.
shar -VxQ `find somedir -print` > archive.sh
If you really want something even simpler, here's a dirt-simple version of shar as a shell script. It takes filenames on standard input instead of arguments for simplicity and to be a little more robust.
#!/bin/sh
while read filename
do
if test -d $filename
then
echo "mkdir -p '$filename'"
else
echo "sed 's/^X//' <<EOF > '$filename'"
sed 's/^/X/' < "$filename"
echo 'EOF'
fi
done
Invoke as:
find somedir -print | simpleshar > archive.sh
You still need to invoke sed, as you need some way of ensuring that no lines in the here document begin with the delimiter, which would close the document and cause later lines to be interpreted as part of the script. I can't think of any really good way to solve the quoting problem using only shell builtins, so you will have to rely on sed (which is standard on any Unix-like system, and has been practically forever).
if your problem are non-text-file-hating filters:
in times long forgotten, we used uuencode to get past 8-bit eating relays -
is that a way to get past attachment eating mail boxes these days ?
So why not zip and uuencode ?
(or base64, which is its younger cousin)