Skip to content

Instantly share code, notes, and snippets.

@riywo
Created August 27, 2012 10:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save riywo/3487347 to your computer and use it in GitHub Desktop.
Save riywo/3487347 to your computer and use it in GitHub Desktop.
#!/bin/bash
_get_kamipo_bin() {
cat <<'EOF' | perl - "${BASH_SOURCE[0]}"
use strict;
use warnings;
use Cwd;
my $path = $ARGV[0] or die;
$path =~ s/^\.\/(.+)$/$1/;
$path = getcwd() . "/$path" if ($path !~ /^\//);
$path =~ s/^(.+)\/etc\/bashrc$/$1/;
print "$path/bin";
EOF
}
_add_kamipo_path() {
local _bin_path=`_get_kamipo_bin`
cat << 'EOF' | perl - "$_bin_path"
use strict;
use warnings;
my $add_path = $ARGV[0] or die;
my @path = split /:/, $ENV{PATH};
unless (grep { $_ eq $add_path } @path) {
push @path, $add_path;
}
print join(":", @path)."\n";
EOF
}
export PATH=`_add_kamipo_path`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment