Last active
July 7, 2021 08:19
-
-
Save orikad/603ea97e33bb9e5ce07f55a36d53bdce to your computer and use it in GitHub Desktop.
Get header paths from the compiler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| if [ -z $1 ] | |
| then | |
| echo "Usage: $0 path/to/system/header.h" | |
| echo "Example: $0 fcntl.h" | |
| echo "Opens header in \$EDITOR ($EDITOR)" | |
| exit -1 | |
| fi | |
| if [ -z $EDITOR ] | |
| then | |
| echo "Warning: \$EDITOR is not set. Fallbacking to \`vim\`." | |
| EDITOR=vim | |
| fi | |
| CC="gcc" | |
| set -o pipefail | |
| fname=$(basename "$1" | sed s/\\./\\\\./) | |
| path=$(echo "#include <$1>" | $CC -x c - -M | grep -o "/.*$fname") | |
| if [ ! -z "$path" ] | |
| then | |
| echo "$path" | |
| IFS=$'\n' | |
| for l in $path | |
| do | |
| $EDITOR "$l" | |
| done | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment