https://github.com/riscy/command_line_lint
This script generates a report against your command-line history and suggests workflow improvements.
https://github.com/riscy/command_line_lint
hacktoberfest linter shell
Last synced: 12 months ago
JSON representation
This script generates a report against your command-line history and suggests workflow improvements.
- Host: GitHub
- URL: https://github.com/riscy/command_line_lint
- Owner: riscy
- License: mit
- Created: 2018-12-28T05:55:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-03-20T15:49:02.000Z (over 2 years ago)
- Last Synced: 2025-04-11T23:53:08.421Z (about 1 year ago)
- Topics: hacktoberfest, linter, shell
- Language: Python
- Homepage:
- Size: 1.05 MB
- Stars: 47
- Watchers: 2
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.org
- License: LICENSE
Awesome Lists containing this project
README
#+TITLE: Command-Line Lint
#+OPTIONS: toc:3 author:t creator:nil num:nil
#+AUTHOR: Chris Rayner
#+EMAIL: dchrisrayner@gmail.com
[[https://github.com/riscy/command_line_lint/actions][https://github.com/riscy/command_line_lint/workflows/test/badge.svg]]
# http://clipart-library.com/clipart/2018521.htm
[[file:img/report_card.png]]
* Description
This script generates a report against your command-line history and suggests
workflow improvements. Its opinion is that most commands should be simple and
require minimal typing. The report contains:
- comprehensive lists of commands you use, with and without arguments
- suggestions for ways to shorten commands (aliases, alternative syntax)
- a subset of lints from [[https://www.shellcheck.net][Shellcheck]], if installed; many of these can warn
against dangerous habits
The script does not use the network, and it doesn't move or store your command
history anywhere. It should be fairly portable, running on Python 2.7 or 3.4+
and requiring "only" the standard library.
This is an early prototype and primarily supports bash, sh, and zsh.
[[file:img/screenshot.png]]
* Run
Download [[https://raw.githubusercontent.com/riscy/command_line_lint/master/command_line_lint.py][command_line_lint.py]] and run it:
#+begin_src bash
python command_line_lint.py # python 2 or 3 is fine
#+end_src
The == argument is optional. If omitted, a determination is
made based on the value of the =SHELL= environment variable:
- =bash= uses =.bash_history=
- =csh= and =tcsh= use =.history=
- =zsh= uses the value of =HISTFILE=
Not all shells have support for saving a history file (fish, dash, etc.)
* Configure
/Command-Line Lint/ gives better results when the following hold
(it will tell you about these, too):
- The =HISTSIZE= environment variable should be large enough to produce useful
usage summaries. The defaults tend to be too small -- try 5000.
- Retaining duplicate entries is important for being able to determine what
you do the most, so variables/options like =bash='s =HISTCONTROL= or =zsh='s
=histignorealldups= should be set appropriately.
- If you use =bash=, ~shopt histappend~ should be set so that multiple
concurrent shell sessions can all add to your =.bash_history=. If you use
=zsh=, ~setopt appendhistory~ should be set likewise.
If you're linting a history file that comes from a different shell than the
one you're using, you can let the script know. For example, .history comes
from a zsh session but you're using bash, you can write:
#+begin_src bash
SHELL=zsh python command_line_lint.py /path/to/.zsh_history
#+end_src
This script supports the use of [[http://no-color.org][NO_COLOR]] to disable color output:
#+begin_src bash
NO_COLOR=1 python command_line_lint.py
#+end_src
* Future
Because those who do not learn from history are doomed to =!!=,
additional reporting around some of the following would be useful:
- Command fingerprinting to sort out common typos (~shopt dirspell~, if it
exists, can be used to fix typos in =cd=)
- Security checks in addition to readability of history file (for example
warnings about plaintext passwords, etc.)
- Analyzing sequences of commands for improvements (e.g., sometimes
dry-running a command like ~rm -rf ./*~ with ~ls ./*~ is a good idea;
switching back and forth between directories can use ~cd -~ and switching
back and forth between git branches can use ~git checkout -~; etc.)