Skip to content

Instantly share code, notes, and snippets.

@orikad
Last active July 7, 2021 08:19
Show Gist options
  • Select an option

  • Save orikad/603ea97e33bb9e5ce07f55a36d53bdce to your computer and use it in GitHub Desktop.

Select an option

Save orikad/603ea97e33bb9e5ce07f55a36d53bdce to your computer and use it in GitHub Desktop.

Revisions

  1. orikad revised this gist Jun 7, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions edit-header.sh
    Original file line number Diff line number Diff line change
    @@ -14,10 +14,10 @@ then
    EDITOR=vim
    fi

    CC="xcrun --run clang"
    CC="gcc"

    set -o pipefail
    fname=$(basename "$1")
    fname=$(basename "$1" | sed s/\\./\\\\./)
    path=$(echo "#include <$1>" | $CC -x c - -M | grep -o "/.*$fname")

    if [ ! -z "$path" ]
  2. orikad created this gist Jan 30, 2020.
    31 changes: 31 additions & 0 deletions edit-header.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    #!/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="xcrun --run clang"

    set -o pipefail
    fname=$(basename "$1")
    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