ohmybash / oh-my-bash

A delightful community-driven framework for managing your bash configuration, and an auto-update tool so that makes it easy to keep up with the latest updates from the community.
https://ohmybash.github.io
MIT License
5.55k stars 626 forks source link

Agnoster issue after updating #417

Closed edoardottt closed 1 year ago

edoardottt commented 1 year ago

Hi, sorry if this is a problem easily fixable but I don't know how oh-my-bash works.

After updating oh-my-bash (agnoster theme) I have an extra green triangle in the prompt that should be there only for git branch info but it's there even blank. Screenshot from 2023-03-14 09-10-06

Moreover, the console prints weird git-related output every time I execute a command (but even with a simple ENTER too) Screenshot from 2023-03-14 09-11-52

akinomyoga commented 1 year ago

Maybe, do you define a command hg as something different from Mercurial's hg?

The upstream speedenator/agnoster-bash added the support for the version control system Mercurial (hg) (https://github.com/speedenator/agnoster-bash/commit/d06166724cc9d6e5cd59a0000f9dd1292db50fe0), and we recently imported the change from the upstream (8c2f1d5049d98c5fe9de6bea827d9d6a4c12a333). When there is a command hg, the Agnoster theme considers it to be Mercurial's CLI command just like Git's git. Then, based on the result of the call of hg, the Agnoster theme considers you are in a Mercurial repository. This results in a new green triangle which is supposed to show the Mercurial repository information.

edoardottt commented 1 year ago

oh yes! I use alias hg="history | grep -i $1".

Is there a way to disable mercurial hg? Cuz I know I won't use that, if not I'll rename hg to something else ..

Thanks for your fast answer !!!!

akinomyoga commented 1 year ago

I think there are many ways to modify it. For example, you can overwrite prompt_hg with an empty function after source "$OSH/oh-my-bash.sh" in ~/.bashrc.

# add this line after "source oh-my-bash.sh" in bashrc
function prompt_hg { return 0; }
akinomyoga commented 1 year ago

I use alias hg="history | grep -i $1".

By the way, 1) $1 in alias hg="history | grep -i $1" would be expanded at the defining time of the alias, but not the expansion time of the alias, so you are probably defining an alias alias hg='history | grep -i ' (if $1 is empty in the defining context). The space at the end of the alias definition would induce another alias expansion for the next argument. 2) Even if the alias is defined as alias hg='history | grep -i $1' (which I think would be your intent), Bash doesn't support $1 in the alias definition like Zsh. The alias will be expanded to the literal $1 in Bash.

You can just define it as

alias hg='history | grep -i'

or if you would like to use positional parameters $1, $2, ...., you need to use shell functions in Bash:

function hg { hsitory | grep -i "$1"; }
edoardottt commented 1 year ago
function prompt_hg { return 0; }

is working super fine. Thanks !!!

I'm using

alias hg="history | grep -i $1"

inside .bashrc and I can confirm is working properly ($1 being replaced to the first argument)

akinomyoga commented 1 year ago

I'm using

alias hg="history | grep -i $1"

inside .bashrc and I can confirm is working properly ($1 being replaced to the first argument)

The above might work in most cases, but that is not working in the way that you expect. As you write it in ~/.bashrc where $1 is normally an empty string, I think the alias definition becomes alias hg='history | grep -i '. You can check the resulting definition of the alias with the following command. What is shown with this command?

$ alias hg

If it reads like alias hg='history | grep -i ', it would cause strange behavior when you try to search a string that matches any of the aliases. For example, the following command wouldn't search 9 because alias 9 is defined by OMB.

$ hg 9
edoardottt commented 1 year ago

Thanks for the explanation. I didn't know that!!!

When using alias hg="history | grep -i $1" i get this

$> alias hg
alias hg='history | grep -i '

and in fact I also have an alias mapping "python" to "python3", executing hg python, I search for python3 and not python (alias expanded)...

with single quotes I got this working properly..

Thank u so much !!!

akinomyoga commented 1 year ago

OK, let me close the issue since the original issue seems to have been solved.