Can I use an alias extension with built-in commands in Git?

I have the following alias in mine .gitconfig:

freq = !history | cut -c 8- | grep ^git | sort | uniq -c | sort -n -r | head -n 5

It should show the 5 git commands that I use the most. Taken from here: http://alblue.bandlem.com/2011/04/git-tip-of-week-aliases.html (I know the article is out of date)

When I run the command, it does not output anything:

$ git freq
$

But if I run history | cut -c 8- | grep ^git | sort | uniq -c | sort -n -r | head -n 5, the output is:

$ history | cut -c 8- | grep ^git | sort | uniq -c | sort -n -r | head -n
   5 git log
   5 git status
   5 git current
   5 git co master
   4 git co other-branch

I assume this is because it historyis a shell built-in command, and if I change the alias freq, for example. in:

freq = !history

I get:

$ git freq
error: cannot run history: No such file or directory
fatal: While expanding alias 'freq': 'history': No such file or directory
$

Is there any way to make it work?

+4
source share
1 answer

Cause

, , history .

git

Git , GIT_TRACE true ( . Git - Scott Chacons Git Book).

$ GIT_TRACE=true git freq

10:14:11.901296 git.c:554               trace: exec: 'git-freq'
10:14:11.901296 run-command.c:341       trace: run_command: 'git-freq'
10:14:11.932496 run-command.c:341       trace: run_command: 'history | tail'
10:14:11.963697 run-command.c:192       trace: exec: '/bin/sh' '-c' 'history | tail' 'history | tail'

, execv_shell_cmd, sane_execvp, -end execvp, - - PATH , . history , , .


, , , - :

Bash , Bash , , exec, . history .


1.

Gilles on Unix Linux , , HISTFILE set -o history, :

bash -c "HISTFILE=~/.bash_history; set -o history; history"

.gitconfig :

freq = "!HISTFILE=$HOME/.bash_history; set -o history; history | cut -c 8- | grep ^git | sort | uniq -c | sort -n -r | head -n 5"

. , Bash, , . Bash, , HISTFILE ​​ , $HOME/.bash_history.

, , HISTFILE, ( git), .

2:

:

freq = !grep ^git $HOME/.bash_history | sort | uniq -c | sort -n -r | head -n 5

, history , , , , .

, cut .

3: Bash

- Git Bash:

alias git-freq='history | cut -c 8- | grep ^git | sort | uniq -c | sort -n -r | head -n

, Id . , Bash, .

, , . .bashrc, , :

# Append history entries on logout - instead of over-writing the history file.
shopt -s histappend

# Don't store duplicate lines in the history.
# Ignore any commands that begin with a space.
HISTCONTROL=ignoredups:ignorespace

# Use a very large history file to store lots of commands.
# See http://mywiki.wooledge.org/BashFAQ/088
HISTFILESIZE=5000
# Keeping a large history requires system resources
HISTSIZE=3000

# Append to the history file after every command.
PROMPT_COMMAND="history -a"
+2

Source: https://habr.com/ru/post/1607773/


All Articles