I'm trying to create a script to convert from $GIT_DIR/info/exclude to .gitignore files. I'd like to put the .gitignore files as close to the pattern target as possible, meaning that a glob like /a/b/*/*.c
should be put in /a/b/.gitignore
. To do this accurately, I need something which can return the longest substring from the start which is uniquely identified, based on man glob
. Does there exist anything like this, preferably something which is portable across *nixes?