0

File path is

/Users/me/Document/project/tests/unittests1/testfile1.js
/Users/me/Document/project/tests/unittests2/testfile2.js

I need to run bash script from project directory. Bash script is in project directory.

The argument to the bash script needs to be unittests/testfile.js instead of the whole path /Users/me/Document/project/tests/unittests/testfile.js

Is there a way tab complete can work if I type just unit as argument and hit tab for tab completion?

SUM
  • 1,651
  • 4
  • 33
  • 57
  • yes, if you `cd` into tests before ;) – alecxs Jul 20 '20 at 20:11
  • :) any other way without doing `cd` into tests? – SUM Jul 20 '20 at 20:12
  • if "Bash script is in project directory", then doesn't the argument to the bash script needs to be `tests/unittests/testfile.js` instead of `unittests/testfile.js` ? – olha Jul 20 '20 at 20:12
  • the way the test framework is built right now its `unittests/testfile.js` – SUM Jul 20 '20 at 20:13
  • also, you can `export` enviroment variable like `export ut=/Users/me/Document/project/tests/unittests/` and `echo $ut ` – olha Jul 20 '20 at 20:14
  • i don't think that TAB will search recursive through entire disk, but of course you could write a script for `find` which will satisfied with pattern *unit* as argument – alecxs Jul 20 '20 at 20:16
  • You can customize completion, so you could probably configure it so that when the command is this particular script, it performs completion relative to the `tests` directory. – Barmar Jul 20 '20 at 20:32
  • [so] is for programming questions, not questions about using or configuring Unix and its utilities. [unix.se] or [su] would be better places for questions like this. – Barmar Jul 20 '20 at 20:32
  • 1
    @Olha Path resolution doesn't have anything to do with the location of the script (at least, by default). Relative paths are resolved based on the current working directory, which is inherited from the working directory of the process that started it (i.e. your shell). If you `cd` to the script's directory before running it, that'll be the script's directory; otherwise, it won't. Reliably resolving paths relative to the location of the script is [actually rather difficult](http://mywiki.wooledge.org/BashFAQ/028). – Gordon Davisson Jul 20 '20 at 21:43
  • The shell script needs to `cd "$(dirname "$0")"` if the PWD of the script is so important. – glenn jackman Jul 20 '20 at 22:16
  • 1
    just answered a similar question yesterday. see https://stackoverflow.com/questions/62979947/ – pynexj Jul 21 '20 at 01:59

0 Answers0