Skip to content

Instantly share code, notes, and snippets.

@nocd5
Created July 7, 2014 12:13
Show Gist options
  • Save nocd5/f34b8c96b07ed13646a5 to your computer and use it in GitHub Desktop.
Save nocd5/f34b8c96b07ed13646a5 to your computer and use it in GitHub Desktop.
function nyaos.command.pcd()
local complst = nyaos.default_complete("", 1)
local buf = ""
for i, e in ipairs(complst) do
-- nyaos.statが通らないので、
-- 末尾のスラッシュ、バックスラッシュを削除
local f = e[2]:gsub('(.+)[\\/]$', '%1')
local stat = nyaos.stat(f)
if (stat and stat.directory) then
buf = buf .. '\n' .. e[2]
end
end
if (buf == "") then
print ("Directory not found.")
return
end
-- pecoはUTF-8じゃなきゃダメなので変換
nyaos.chdir(nyaos.eval("echo " .. buf ..
" | iconv -f SJIS -t UTF-8 \
| peco \
| iconv -f UTF-8 -t SJIS"))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment