Skip to content

Instantly share code, notes, and snippets.

@DeaR
Last active December 11, 2015 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeaR/4663369 to your computer and use it in GitHub Desktop.
Save DeaR/4663369 to your computer and use it in GitHub Desktop.
Force expand of Unix style environment variable for NYAOS 3.x
-- Force expand of Unix style environment variable for NYAOS 3.x
--
-- Maintainer: DeaR <nayuri@kuonn.mydns.jp>
-- Last Change: 14-Aug-2013.
-- License: MIT License {{{
-- Copyright (c) 2013 DeaR <nayuri@kuonn.mydns.jp>
--
-- Permission is hereby granted, free of charge, to any person obtaining a
-- copy of this software and associated documentation files (the
-- "Software"), to deal in the Software without restriction, including
-- without limitation the rights to use, copy, modify, merge, publish,
-- distribute, sublicense, and/or sell copies of the Software, and to
-- permit persons to whom the Software is furnished to do so, subject to
-- the following conditions:
--
-- The above copyright notice and this permission notice shall be included
-- in all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-- }}}
function nyaos.filter.unix_env_expand(c)
function x(e)
return '%' .. e .. '%'
end
function y(d, e)
return d .. '%' .. e .. '%'
end
return c:gsub('^%$%{([%w_./]+)%}', x):gsub('([^$])%$%{([%w_./]+)%}', y):gsub('^%$([%w_]+)', x):gsub('([^$])%$([%w_]+)', y):gsub('%$%$', '$')
end
-- vim: ft=lua

unix_env_expand.lua

Force expand of Unix style environment variable for NYAOS 3.x

Install

  1. Checkout the source from repository

    git clone https://gist.github.com/4663369.git unix_env_expand
  2. add to _nya

    source unix_env_expand/unix_env_expand.lua

Usage

  • echo "$OS"
  • alias ls "if $$1 == ""x"" then ; echo ahaha ; end if"

Issue

Author

DeaR (nayuri@kuonn.mydns.jp)

@nayuri_aohime

License

Copyright (c) 2013 DeaR <nayuri@kuonn.mydns.jp>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@DeaR
Copy link
Author

DeaR commented Jan 29, 2013

ダブルクォーテーションで囲まれたUnixStyle環境変数が展開されなかったのを無理やり展開
しかしながら、素直にWindowsStyleで書けば良いのは言うまでもない
ぶっちゃけ使ってない

@DeaR
Copy link
Author

DeaR commented Jan 29, 2013

一応、当スクリプトの有る無しでecho "%OS% -- ${OS}"とかすれば違いが分かるとおも

@DeaR
Copy link
Author

DeaR commented Jan 29, 2013

考えてみるとaliasのマクロに誤爆すんな(´-`).。oO(・・・・・・・・・)

@DeaR
Copy link
Author

DeaR commented Jan 30, 2013

alias ls "if $$1 == ""x"" then ; echo ahaha ; end if"
の様に$を重ねる必要があります
(まぁ、使ってないんで細かくはシラネ)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment