Sha256: 34d46dbfd569cd387c6c45bae485d42527162afe230b3dc9a20a2944a981e433

Contents?: true

Size: 1.09 KB

Versions: 33

Compression:

Stored size: 1.09 KB

Contents

#!/usr/bin/env ruby

require 'tins/go'
include Tins::GO
require 'tins/xt/secure_write'
require 'tempfile'

path_separator = RUBY_PLATFORM =~ /mswin32/ ? ';' : ':'
path = (ENV['PATH'] || '').split(path_separator)
path.map! { |part| File.expand_path(part) }

$opts = go('e')

case cmd = ARGV.shift
when 'prefix', 'postfix'
  part = ARGV.shift or fail 'need a path part to prefix'
  part = File.expand_path(part)
  path.delete part
  if cmd == 'prefix'
    path.unshift part
  else
    path.push part
  end
when 'list'
  if path_argument = ARGV.first
    path = path_argument.split(path_separator)
    path.map! { |part| File.expand_path(part) }
  end
  puts path
  exit
when 'edit'
  if path_argument = ARGV.first
    path = path_argument.split(path_separator)
    path.map! { |part| File.expand_path(part) }
  end
  path_file = File.join(Dir.tmpdir, "path_temp.#$$")
  File.secure_write path_file, path * "\n"
  system "edit -w #{path_file.inspect}"
  path = File.read(path_file).split(/\n/)
  path.map! { |part| File.expand_path(part) }
end

path.uniq!

puts "#{'export ' if $opts[?e]}PATH=#{path * path_separator}"

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
utils-0.60.1 bin/path
utils-0.60.0 bin/path
utils-0.59.2 bin/path
utils-0.59.1 bin/path
utils-0.59.0 bin/path
utils-0.58.0 bin/path
utils-0.57.1 bin/path
utils-0.57.0 bin/path
utils-0.56.1 bin/path
utils-0.56.0 bin/path
utils-0.55.0 bin/path
utils-0.54.1 bin/path
utils-0.54.0 bin/path
utils-0.53.1 bin/path
utils-0.53.0 bin/path
utils-0.52.1 bin/path
utils-0.52.0 bin/path
utils-0.51.1 bin/path
utils-0.51.0 bin/path
utils-0.50.0 bin/path