Skip to content

Conversation

@blueyed
Copy link
Contributor

@blueyed blueyed commented Apr 6, 2016

Fixes #70.

TODO:

  • port it for plat/win32/update_tags.cmd

@ludovicchabant
Copy link
Owner

Hi, thanks but I don't want a dependency on Python so we'll have to find a different implementation...

When the cache dir is not set (i.e. when we store the tags file at the project root) we already run a chdir in Vim before running the script so I think making the file path relative in that same if block would solve your problem no?

@blueyed
Copy link
Contributor Author

blueyed commented Jul 5, 2016

I am using the script itself also outside of Vim, e.g. from a Git hook - so it should be done in the script.
It could be done in shell code, too - but having it in POSIX (/bin/sh shebang) certainly does not make it easier. But I do not want to switch to using bash for the script just because of this, too.

# This is required for consistent naming.
# See https://github.com/ludovicchabant/vim-gutentags/issues/70.
relpath() {
python -c "import os.path; print(os.path.relpath('$1', '${2}'))"
Copy link

@ZyX-I ZyX-I Jul 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not going to work if path contains backslash, single quote or some of the control characters. Should be

A="$1" B="$2" python -c 'import os; print(os.path.relpath(os.environ["A"], os.environ["B"]))'

(you may also pass this as an argument after -c command, but this would require two imports).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, but we need something without Python anyway.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know only one way so far: ln --relative --symbolic with readlink. But this is GNU-coreutils-specific, BSD ln seems to not have this argument. I am wondering why you want exactly relative path? It seems that absolute path is easier to construct:

abspath() {(
    test "x$2" '!=' "x" && cd "$2"
    cd "$(dirname "$1")"
    printf '%s/%s\n' "$(pwd)" "$(basename "$1")"
)}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember.. but it will be shorter at least.

@ludovicchabant
Copy link
Owner

I did what I said (make the file path relative in Vimscript) with commit 09fbdfc. If you run the script from a git hook you shouldn't have problems passing that path to the script in a relative way, no? (since the hook itself runs in the git repo AFAIK).

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

Successfully merging this pull request may close these issues.

3 participants