Sha256: abfd6b8e2f2394a9f33e711b3a86b6758b86fb575dad1dda1960e2097a1873a3

Contents?: true

Size: 952 Bytes

Versions: 25

Compression:

Stored size: 952 Bytes

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 '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

25 entries across 25 versions & 1 rubygems

Version Path
utils-0.37.1 bin/path
utils-0.37.0 bin/path
utils-0.36.0 bin/path
utils-0.35.0 bin/path
utils-0.34.0 bin/path
utils-0.33.1 bin/path
utils-0.33.0 bin/path
utils-0.32.0 bin/path
utils-0.31.1 bin/path
utils-0.31.0 bin/path
utils-0.30.2 bin/path
utils-0.30.1 bin/path
utils-0.30.0 bin/path
utils-0.29.0 bin/path
utils-0.28.0 bin/path
utils-0.27.0 bin/path
utils-0.26.1 bin/path
utils-0.26.0 bin/path
utils-0.25.0 bin/path
utils-0.24.2 bin/path