File: script-dir

package info (click to toggle)
yasnippet-snippets 1.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,328 kB
  • sloc: lisp: 127; sh: 13; ada: 5; makefile: 2; python: 2
file content (14 lines) | stat: -rw-r--r-- 615 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# -*- mode: snippet -*-
# name: the currently executing/sourced script's directory
# key: script-dir
# --
# See https://stackoverflow.com/a/246128/3561275
SOURCE="\${BASH_SOURCE[0]}"
while [ -h "\$SOURCE" ]; do # resolve \$SOURCE until the file is no longer a symlink
  DIR="\$( cd -P "\$( dirname "\$SOURCE" )" >/dev/null 2>&1 && pwd )"
  SOURCE="\$(readlink "\$SOURCE")"
  [[ \$SOURCE != /* ]] && SOURCE="\$DIR/\$SOURCE" # if \$SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="\$( cd -P "\$( dirname "\$SOURCE" )" >/dev/null 2>&1 && pwd )"

$0