5

watch command doesn't work for alias commands.

Without alias:

➜  scrcpy git:(master) git -P branch
* master
➜  scrcpy git:(master) watch git branch

enter image description here

With alias

➜  scrcpy git:(master) which gb
gb: aliased to git branch
➜  scrcpy git:(master) watch gb

enter image description here

Pablo Bianchi
  • 14,308
  • 4
  • 74
  • 117
Rajesh Chaudhary
  • 861
  • 1
  • 13
  • 25

1 Answers1

8

You will need to alias watch as well for this to work. It needs space around the command, i.e. alias watch='watch ' and after the space it is expecting the next part to be an alias as well.

So, we will create an alias with the -n in it as well. Since you are doing every 2 seconds create a new alias to watch every 2 seconds.

alias watch-2='watch -n 2 '

Then you would just run it as

watch-2 gb

Hope this helps!

Terrance
  • 39,774
  • 7
  • 116
  • 176
  • Have you got any idea just to set aias as `watch` so that any built-in arguments like `-n` can be passed dynamically? e.g `watch -n4 gb` – Rajesh Chaudhary Dec 10 '20 at 05:26
  • @RajeshChaudhary Unfortunately, it doesn't work that way. To watch an alias you have to have an alias of it. So, for 4 seconds it would be the same here but with 4. I can't see any other way around it. – Terrance Dec 10 '20 at 14:29