Skip to content

Instantly share code, notes, and snippets.

@snipsnipsnip
Last active August 24, 2019 15:17
Show Gist options
  • Save snipsnipsnip/14332 to your computer and use it in GitHub Desktop.
Save snipsnipsnip/14332 to your computer and use it in GitHub Desktop.
starts windows cmd in short path (requires ruby)
@ruby -x "%~f0" %*
@exit /b
#!ruby -Ks
require 'Win32API'
GetShortPathName = Win32API.new('kernel32', 'GetShortPathName', 'ppi', 'i')
def get_short_path_name(path)
len = GetShortPathName.call(path, nil, 0)
raise if len.zero?
buffer = "\0" * len
GetShortPathName.call(path, buffer, len)
buffer.tr('/', '\\')
end
Dir.chdir get_short_path_name(Dir.pwd)
exec ENV['COMSPEC']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment