Skip to content

Instantly share code, notes, and snippets.

@chikadance
Created April 18, 2013 01:17
Show Gist options
  • Save chikadance/5409129 to your computer and use it in GitHub Desktop.
Save chikadance/5409129 to your computer and use it in GitHub Desktop.
bash-like alias
$file_path = 'd:/360cloud/tool/alias.psm1'
class Set_Alias
def create
p 'create'
file = File.new($file_path, 'a')
file.puts
file.puts "Function #{@ali} { #{@ori} }"
file.close
end
def modify
p 'modify'
content = File.read($file_path)
content.gsub!(/Function #{@ali} \{.*\}/, "Function #{@ali} { #{@ori} }")
File.open($file_path, 'w').puts content
end
def initialize(ali, ori)
@ali, @ori = ali, ori
end
end
ali, ori = ARGV[0], ARGV[1]
set_alias = Set_Alias.new(ali, ori)
content = File.read $file_path
if content[/Function\s#{ali}.*/]
set_alias.modify
else
set_alias.create
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment