crclark96 / ginh Goto Github PK
View Code? Open in Web Editor NEWginh is not a histogram: visually evaluate your shell usage patterns
License: MIT License
ginh is not a histogram: visually evaluate your shell usage patterns
License: MIT License
11:01:02 [carbolymer:/tmp]↥ % ./ginh.sh
entries=15, file=/home/carbolymer/.zhistory, char==, len=168
grep: /home/carbolymer/.zhistory: No such file or directory
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
===================================================================================================================================================================== 1
=
=
=
=
=
=
=
=
=
=
=
=
=
=
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
11:01:07 [carbolymer:/tmp]↥ % stat /home/carbolymer/.zhistory
File: /home/carbolymer/.zhistory
Size: 447249 Blocks: 880 IO Block: 4096 regular file
Device: 804h/2052d Inode: 528724 Links: 1
Access: (0600/-rw-------) Uid: ( 1000/carbolymer) Gid: ( 1000/carbolymer)
Access: 2019-01-28 11:00:26.039894271 +0100
Modify: 2019-01-28 10:50:32.299924404 +0100
Change: 2019-01-28 10:50:32.299924404 +0100
Birth: -
./ginh.sh
[2] + 27930 suspended (tty input) ./ginh.sh
./ginh.sh -h
[3] + 12944 suspended (tty input) ./ginh.sh -h
instead, It works as expected on bash
bash
./ginh.sh
entries=15, file=/home/x/.bash_history, char==, len=209
...
it gets me output when I run fg
On the most recent commit (after switching alias reversing and sudo filter), sudo
still appears as an entry in my top commands
ginh on master [$]
➜ ./ginh.sh
entries=15, file=/home/crclark/.zsh_history, char==, len=86
---------------------------------------------------------------------------------------
git ============================================================================ 1926
cd ================================================ 1231
ls ============================================= 1145
make ================================= 844
java =========================== 679
cat ======================= 575
vim ==================== 498
sudo ================= 412
open ============== 341
mv ======== 192
rm ======= 178
fg ===== 128
dot ==== 97
cp ==== 93
man ==== 89
---------------------------------------------------------------------------------------
Great Script! It doesn't work with ZSH History files though, as they are formated differently. The following should work:
calc=$(cat $histfile | sed s/sudo//g | awk -F ';' '{print $2}' | awk '{print $1}' | sort | uniq -c | sort -rn)
I also included a sed command to strip sudo out, as all sudo commands are counted the same. But that's just, because i'm more interested in what i actually did with sudo. One could output two graphs, one for Sudo commands and one without.
Maybe the current shell can be recieved programatically with "echo $0" and handle the histfile and calculation depending on what's returned.
Describe the bug
Using the -d flag to get the debug output prints the commit hash of the HEAD of the repo. If ginh is run from inside this repo that's fine, however, if it is installed and run, it gives
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
commit:
And if it is installed and run from inside another git repo, it will give a hash from that repo, which is useless.
Debug
See above
grep --help
as an example, provides each flag with a short description of its features
ginh on patch-28 took 2s
➜ grep --help
Usage: grep [OPTION]... PATTERN [FILE]...
Search for PATTERN in each FILE.
Example: grep -i 'hello world' menu.h main.c
Pattern selection and interpretation:
-E, --extended-regexp PATTERN is an extended regular expression
-F, --fixed-strings PATTERN is a set of newline-separated strings
-G, --basic-regexp PATTERN is a basic regular expression (default)
-P, --perl-regexp PATTERN is a Perl regular expression
-e, --regexp=PATTERN use PATTERN for matching
-f, --file=FILE obtain PATTERN from FILE
-i, --ignore-case ignore case distinctions
-w, --word-regexp force PATTERN to match only whole words
-x, --line-regexp force PATTERN to match only whole lines
-z, --null-data a data line ends in 0 byte, not newline
> ./ginh.sh -f /Users/sortega/.zsh_history
entries=15, file=/Users/sortega/.zsh_history, char==, len=110
sort: Illegal byte sequence
./ginh.sh: line 101: freq[n]=counts[n] * 107 / counts[0] : division by 0 (error token is " ")
./ginh.sh: line 101: freq[n]=counts[n] * 107 / counts[0] : division by 0 (error token is " ")
./ginh.sh: line 101: freq[n]=counts[n] * 107 / counts[0] : division by 0 (error token is " ")
./ginh.sh: line 101: freq[n]=counts[n] * 107 / counts[0] : division by 0 (error token is " ")
./ginh.sh: line 101: freq[n]=counts[n] * 107 / counts[0] : division by 0 (error token is " ")
./ginh.sh: line 101: freq[n]=counts[n] * 107 / counts[0] : division by 0 (error token is " ")
./ginh.sh: line 101: freq[n]=counts[n] * 107 / counts[0] : division by 0 (error token is " ")
./ginh.sh: line 101: freq[n]=counts[n] * 107 / counts[0] : division by 0 (error token is " ")
./ginh.sh: line 101: freq[n]=counts[n] * 107 / counts[0] : division by 0 (error token is " ")
./ginh.sh: line 101: freq[n]=counts[n] * 107 / counts[0] : division by 0 (error token is " ")
./ginh.sh: line 101: freq[n]=counts[n] * 107 / counts[0] : division by 0 (error token is " ")
./ginh.sh: line 101: freq[n]=counts[n] * 107 / counts[0] : division by 0 (error token is " ")
./ginh.sh: line 101: freq[n]=counts[n] * 107 / counts[0] : division by 0 (error token is " ")
./ginh.sh: line 101: freq[n]=counts[n] * 107 / counts[0] : division by 0 (error token is " ")
./ginh.sh: line 101: freq[n]=counts[n] * 107 / counts[0] : division by 0 (error token is " ")
---------------------------------------------------------------------------------------------------------------
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
---------------------------------------------------------------------------------------------------------------
When specifying the history file to use with the -f flag, ginh.sh prints an error message that states: ./ginh.sh: line 95: -ci: command not found
. This occurs because when the file is specified, ginh doesn't attempt to determine the user's shell, but during alias reversal, it attempts to invoke the shell, which is not populated.
➜ ginh git:(master) ./ginh.sh -d
commit: e79b710ce37fa0681854cdacd662b1ba7652761b
uname: Linux commodus 5.2.5-arch1-1-ARCH #1 SMP PREEMPT Wed Jul 31 08:30:34 UTC 2019 x86_64 GNU/Linux
shell: zsh
histfile: /home/ryan/.zsh_history
Is your feature request related to a problem? Please describe.
These days I primarily use doas, not sudo.
Describe the solution you'd like
A doas filter to match the existing sudo filter in functionality.
sed: 1: "s|\<_|g; ": unterminated substitute in regular expression
entries=1, file=/home/vagrant/.bash_history, char==, len=115
--------------------------------------------------------------------------------------------------------------------
================================================================================================================ 1
--------------------------------------------------------------------------------------------------------------------
-bash-5.0$ alias
-bash-5.0$ echo "alias t='echo Hello'" >> ~/.bashrc
-bash-5.0$ source .bashrc
-bash: .bashrc: No such file or directory
-bash-5.0$ source ~/.bashrc
-bash-5.0$ t
Hello
-bash-5.0$ t
Hello
-bash-5.0$ t
Hello
-bash-5.0$ t
Hello
-bash-5.0$ t
Hello
-bash-5.0$ history -a
-bash-5.0$ ./ginh.sh
entries=6, file=/home/vagrant/.bash_history, char==, len=115
--------------------------------------------------------------------------------------------------------------------
git ====================================================================================================== 11
echo ======================================================== 6
./ginh.sh ============================================== 5
history ============================ 3
cd ========== 1
alias ========== 1
--------------------------------------------------------------------------------------------------------------------
-bash-5.0$
As an Ubuntu user, it would be nice if instead of detecting sudo apt get update
as sudo
it would count towards apt
Great and useful script! Though when I tried it it did not work for fish shell :/
So I played around and via "quick fixes" I was able to run it on fish shell and there are 2 problems.
First is that line https://github.com/crclark96/ginh/blob/master/ginh.sh#L62 where variable$calc
needs awk $3 instead of $1 -- grep -v -E '^\s*$|^\s+' $histfile | awk '{print $3}' | sort | uniq -c | sort -rn
to work with fish history file.
Btw fish history file looks like
- cmd: git commit -v -a
when: 1548438622
- cmd: git push origin master
when: 1548438636
- cmd: fg
when: 1548438726
- cmd: head fish_history
when: 1548438886
paths:
- fish_history
And second problem is that $PPID doesn't work in fish shell or is empty. Plus line https://github.com/crclark96/ginh/blob/master/ginh.sh#L9 give strange error fish: Unknown command 'i'
That's all for quick report so yeah. This is awesome tool and it would be awesome have it supported by fish shell history logs. So yeah please add support for fish shell 🙏
Thanks ;)
ps: quick fixes - axeII@abd35aa
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.