Skip to content

Instantly share code, notes, and snippets.

@michaelpass
Last active April 6, 2019 06:49
Show Gist options
  • Save michaelpass/c6906f3651c94bb879c1af4f6aee92c7 to your computer and use it in GitHub Desktop.
Save michaelpass/c6906f3651c94bb879c1af4f6aee92c7 to your computer and use it in GitHub Desktop.

Revisions

  1. michaelpass revised this gist Jan 17, 2019. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions LovelyScript.sh
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,14 @@
    # _ / /\__ \ | | | | | (__
    # (_)___|___/_| |_|_| \___|


    # Deduplicate path variables
    get_var () {
    eval 'printf "%s\n" "${'"$1"'}"'
    }
    set_var () {
    eval "$1=\"\$2\""
    }
    dedup_pathvar () {
    pathvar_name="$1"
    pathvar_value="$(get_var "$pathvar_name")"
  2. michaelpass created this gist Jan 17, 2019.
    15 changes: 15 additions & 0 deletions LovelyScript.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    # _
    # _______| |__ _ __ ___
    # |_ / __| '_ \| '__/ __|
    # _ / /\__ \ | | | | | (__
    # (_)___|___/_| |_|_| \___|

    dedup_pathvar () {
    pathvar_name="$1"
    pathvar_value="$(get_var "$pathvar_name")"
    deduped_path="$(perl -e 'print join(":",grep { not $seen{$_}++ } split(/:/, $ARGV[0]))' "$pathvar_value")"
    set_var "$pathvar_name" "$deduped_path"
    }
    dedup_pathvar PATH
    dedup_pathvar MANPATH
    dedup_pathvar PYTHONPATH