Skip to content

Instantly share code, notes, and snippets.

@DeaR
Last active December 11, 2015 15:19
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/4620297 to your computer and use it in GitHub Desktop.
Save DeaR/4620297 to your computer and use it in GitHub Desktop.
Global alias for NYAOS 3.x
-- Global alias for NYAOS 3.x
--
-- Maintainer: DeaR <nayuri@kuonn.mydns.jp>
-- Last Change: 13-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.
-- }}}
local galias_table = {}
local galias_exclude = {'galias', 'ungalias'}
function nyaos.filter.galias(cmdline)
for i = 1, #galias_exclude do
if cmdline:match('^%s*' .. galias_exclude[i] .. '%s') then
return cmdline
end
end
for k, v in pairs(galias_table) do
cmdline = cmdline:gsub('^' .. k .. '(%s)', v .. '%1'):gsub('(%s)' .. k .. '$', '%1' .. v):gsub('(%s)' .. k .. '(%s)', '%1' .. v .. '%2')
end
return cmdline
end
function nyaos.command.galias(cmd, ...)
if cmd then
local arg = table.concat({...}, ' ')
if arg:len() > 0 then
galias_table[cmd] = arg
elseif galias_table[cmd] then
print(cmd .. ' ' .. galias_table[cmd])
end
else
for k, v in pairs(galias_table) do
print(k .. ' ' .. v)
end
end
end
function nyaos.command.ungalias(cmd)
if cmd then
galias_table[cmd] = nil
else
for k, v in pairs(galias_table) do
print(k .. ' ' .. v)
end
end
end
-- vim: ft=lua

galias.lua

Global alias for NYAOS 3.x

Install

  1. Checkout the source from repository

    git clone https://gist.github.com/4620297.git galias
  2. add to _nya

    source galias/galias.lua

Usage

  • galias L "| less"
  • galias T "| tail"
  • ungalias L

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment