Sha256: 8928e804fda9742ae189054aa3dedab93b5f030e9495f908a66ac07b11ec1385

Contents?: true

Size: 1.11 KB

Versions: 8

Compression:

Stored size: 1.11 KB

Contents

#! /usr/bin/ruby -w

class String
  
  # Add backslash escape at the characters that have perticular meaning in zsh.
  def escape_zsh
    temp = dup
    temp.gsub!('\\', '\\\\\\') # This must be at first, not to substitute other results.
    #temp.gsub!('/', '/') # / is not for escape, due to directory separator.
    temp.gsub!(' ', '\ ') ; temp.gsub!('!', '\!') ; temp.gsub!('"', '\"') ;
    temp.gsub!('#', '\#') ; temp.gsub!('$', '\$') ; temp.gsub!('%', '\%') ;
    temp.gsub!(')', '\)') ; temp.gsub!('(', '\(') ; temp.gsub!('*', '\*') ;
    temp.gsub!(',', '\,') ; #temp.gsub!('-', '\-') ; #temp.gsub!('.', '\.') ;
    temp.gsub!(':', '\:') ; temp.gsub!(';', '\;') ; temp.gsub!('<', '\<') ;
    temp.gsub!('=', '\=') ; temp.gsub!('>', '\>') ; temp.gsub!('?', '\?') ;
    temp.gsub!('@', '\@') ; temp.gsub!('[', '\[') ; temp.gsub!(']', '\]') ;
    temp.gsub!('^', '\^') ; temp.gsub!('_', '\_') ; temp.gsub!('{', '\{') ;
    temp.gsub!('|', '\|') ; temp.gsub!('}', '\}') ; temp.gsub!('~', '\~') ;
    temp.gsub!('`', '\\\`') ; temp.gsub!('&', '\\\&') ;
    temp.gsub!('+', '\\\+') ; temp.gsub!("'", "\\\\'") ;
    return temp
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
builtinextension-0.1.4 lib/string/escapezsh.rb
builtinextension-0.1.3 lib/string/escapezsh.rb
builtinextension-0.1.2 lib/string/escapezsh.rb
builtinextension-0.1.1 lib/string/escapezsh.rb
builtinextension-0.1.0 lib/string/escapezsh.rb
builtinextension-0.0.5 lib/string_escape_zsh.rb
builtinextension-0.0.4 lib/string_escape_zsh.rb
builtinextension-0.0.3 lib/string_escape_zsh.rb