Skip to content

Instantly share code, notes, and snippets.

@AndersDJohnson
Last active June 5, 2019 13:33

Revisions

  1. AndersDJohnson revised this gist Apr 1, 2013. 1 changed file with 25 additions and 0 deletions.
    25 changes: 25 additions & 0 deletions abs_dirname.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    # from: https://github.com/zimbatm/direnv/blob/3bb35d375331fca89614f0015b2a6cd21688ab79/bin/direnv
    # usage: abs_dirname $filename
    # finds the original $filename path and prints it's absolute folder path
    abs_dirname() {
    prev_path="$1"
    # Resolve the symlink(s) recursively
    while true; do
    abs_path=`readlink "$prev_path"`
    if [ -z "$abs_path" ]; then
    abs_path="$prev_path"
    break
    else
    prev_path="$abs_path"
    fi
    done
    unset prev_path

    # Get the absolute directory of the final $abs_path
    orig_dir=`pwd`
    cd `dirname "$abs_path"`
    # prints an absolute path here
    pwd
    cd "$orig_dir"
    unset abs_path orig_dir
    }
  2. AndersDJohnson renamed this gist Feb 11, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. AndersDJohnson revised this gist Feb 11, 2013. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    #!/bin/bash

    BASEDIR=$(dirname "$(readlink -f $0)")

  4. AndersDJohnson revised this gist Jan 13, 2013. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion basedir.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@
    #!/bin/bash

    CURDIR=${PWD}
    BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
    BASEDIR="$( cd "$( dirname "$(realpath $BASH_SOURCE)" )" && pwd )"

    # This didn't support symlinked scripts
    # BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  5. AndersDJohnson created this gist Dec 9, 2012.
    4 changes: 4 additions & 0 deletions basedir.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    #!/bin/bash

    CURDIR=${PWD}
    BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"