Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add home to source paths #1845

Open
2 tasks done
LiterallyUniqueLogin opened this issue Feb 23, 2020 · 3 comments
Open
2 tasks done

Add home to source paths #1845

LiterallyUniqueLogin opened this issue Feb 23, 2020 · 3 comments

Comments

@LiterallyUniqueLogin
Copy link

For bugs

  • Rule Id (if any, e.g. SC1090):
  • My shellcheck version (shellcheck --version or "online"): 0.7.0
  • The rule's wiki page does not already cover this (e.g. https://shellcheck.net/wiki/SC1090)
  • I tried on shellcheck.net and verified that this is still a problem on the latest commit

Here's a snippet or screenshot that shows the problem:

I've set the flags

-P /home/username/ -P /
#!/bin/bash
source ~/.bashrc

Here's what shellcheck currently says:

SC1090: Can't follow non-constant source. Use a directive to specify location.

Here's what I wanted or expected to see:

I wanted shellcheck to find .bashrc in /home/username/.bashrc and not show a warning.
If I insert

 # shellcheck source=/home/username/.bashrc

above this line, shellcheck finds the file and doesn't show a warning (but if I misspell the file name then shellcheck still warns), so my overall usage of shellcheck isn't borked.

Is there any way I can use source paths or some other feature to tell shellcheck where my home will be without having to specify a directive each time?

@b0o
Copy link

b0o commented Sep 22, 2020

I would appreciate this as well. There are often times where I need to source a file in the user's home directory, e.g. ~/.config/foo, and I end up needing to hard-code my own home directory path to satisfy shellcheck. I feel this looks sloppy when shared with others (see my neuron-autoindex script for an example).

Related issue: #507

@tycho-kirchner
Copy link

Just wanted to document here, that using $HOME instead of ~ works nicely (together with -x -P $HOME).
Script test.sh:

#!/usr/bin/env bash
source "$HOME/.lib/bash_commons.sh" || exit
echo "scriptdir $scriptdir"  # scriptdir is set in my bash_commons.sh

Run shellcheck with:

shellcheck -x -P $HOME ./test.sh

s. also here

@ELLIOTTCABLE
Copy link

There's no way to set this in a .shellcheckrc, is there, since $HOME is being expanded by the shell in the above approach?

Unfortunately, that workaround doesn't work very well with IDEs … hrm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants