hwatch icon indicating copy to clipboard operation
hwatch copied to clipboard

[Bug] does not load dotfiles

Open jtara1 opened this issue 6 months ago • 2 comments

I have an alias, l

alias l='ls -lhF --color'

set in a file sourced by ~/.profile

It's unclear why I can see the alias running

hwatch --shell 'bash -l -c' alias l

but I can't use the alias using

hwatch --shell 'bash -l -c' l

Am I using the wrong options? Is this a bug for anyone else?

jtara1 avatar Feb 20 '24 03:02 jtara1

viddy is looking like a great watch alternative too

jtara1 avatar Feb 27 '24 00:02 jtara1

Probably the alias expansion is happening on the shell side you are running.

Are you using zsh as a shell? In my environment with zsh, the execution command is expanded and passed to hwatch.

If the shell invoking hwatch was bash, the alias could be executed without being expanded on the shell side.

blacknon avatar Mar 04 '24 06:03 blacknon

I'm using bash.

These didn't work

hwatch --shell 'bash -l -c' 'source ~/.aliases && l'
hwatch --shell 'bash -l -c' 'shopt -s expand_aliases && l'

jtara1 avatar Mar 18 '24 02:03 jtara1

I believe this is a bash specification. Due to bash specifications, aliases are not expanded when not in interactive mode. This seems to be the same even when the -l option is added.

https://linux.die.net/man/1/bash

Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt (see the description of shopt under SHELL BUILTIN COMMANDS below).

Even if you run it without going through hwatch, the alias will not run.

$ bash -l -c 'shopt -s expand_aliases && l'
bash: line 1: l: command not found
$ bash -l -c 'source ~/.profile && l'
bash: line 1: l: command not found

In other words, if you can find a way to run aliases without going through hwatch, you might be able to run aliases on hwatch as well. So I did some research and found that it doesn't work if aliases are specified on the same line in the first place. https://unix.stackexchange.com/a/502261

$ bash -l -c 'shopt -s expand_aliases && l /hoge'
bash: line 1: l: command not found
$ bash -l -c 'shopt -s expand_aliases'$'\n''l /hoge'
ls: cannot access '/hoge': No such file or directory

So, if you run the command as shown below, I think alias will work with hwatch as well.

hwatch -n 2 --shell 'bash -O expand_aliases -l -c "'$'\n''{COMMAND}"' 'l'

blacknon avatar Mar 23 '24 08:03 blacknon

I think it's resolved, so I'll close the issue.

blacknon avatar Mar 24 '24 13:03 blacknon