mkalias-1.0.10/0000755000004100000410000000000012733017277013253 5ustar www-datawww-datamkalias-1.0.10/Rakefile0000644000004100000410000000016212733017277014717 0ustar www-datawww-datarequire 'bundler/gem_tasks' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) task default: :spec mkalias-1.0.10/bin/0000755000004100000410000000000012733017277014023 5ustar www-datawww-datamkalias-1.0.10/bin/console0000755000004100000410000000051412733017277015413 0ustar www-datawww-data#!/usr/bin/env ruby require 'bundler/setup' require 'mkalias' # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. # (If you use this, don't forget to add pry to your Gemfile!) # require "pry" # Pry.start require 'irb' IRB.start mkalias-1.0.10/bin/mkalias0000755000004100000410000000460412733017277015376 0ustar www-datawww-data#!/usr/bin/env ruby require 'mkalias' require 'usage' VALID_OPTIONS = %w(new list show remove add_signal remove_signal).freeze def usage puts Usage.header puts Usage.option_new puts Usage.option_list puts Usage.option_show puts Usage.option_remove puts Usage.option_signals puts Usage.attention abort end def new usage if ARGV.count < 3 alias_name = ARGV[1] commands = ARGV[2..-1] result = Mkalias.new_alias(alias_name, commands) if result puts " - Created Alias: #{alias_name}" check_signal else puts " ERROR: O Alias [#{alias_name}] já existe" end end def list alias_names = Mkalias.list_alias puts 'Registered Alias:' alias_names.each do |alias_name| puts " - #{alias_name}" end end def check_alias_exists(alias_list, used_alias_names) alias_not_founded = alias_list - used_alias_names unless alias_not_founded.empty? alias_not_founded = alias_not_founded.join(', ') puts "Alias not founded: #{alias_not_founded}" puts '' end end def show alias_names = ARGV.count < 2 ? Mkalias.list_alias : ARGV[1..-1] commands = Mkalias.show_alias(alias_names) check_alias_exists(alias_names, commands.keys) unless commands.empty? commands.each do |alias_name, alias_commands| puts "-> #{alias_name}" alias_commands.each { |alias_command| puts " $ #{alias_command}" } puts '' end end end def remove usage if ARGV.count < 2 alias_names = ARGV[1..-1] removed_alias = Mkalias.remove_alias(alias_names) check_alias_exists(alias_names, removed_alias) unless removed_alias.empty? puts 'Removed Alias:' removed_alias.each { |alias_name| puts "- #{alias_name}" } check_signal end end def add_signal result = Mkalias.add_signal if result puts "Add signal to call 'source ~/.bashrc'" puts " - Run '$ source ~/.bashrc' to update your bash" else puts 'The signal has already been added' end end def remove_signal result = Mkalias.remove_signal if result puts 'The signal was removed' puts " - Run '$ source ~/.bashrc' to update your bash" else puts 'The signal does not exist to be removed' end end def check_signal if Mkalias.signal? `kill -USR1 #{Process.ppid}` else puts " - Run '$ source ~/.bashrc' to use your alias" end end def main usage if ARGV.count == 0 || !VALID_OPTIONS.include?(ARGV[0]) option = ARGV[0] send(option.to_s) end main mkalias-1.0.10/bin/setup0000755000004100000410000000020312733017277015104 0ustar www-datawww-data#!/usr/bin/env bash set -euo pipefail IFS=$'\n\t' set -vx bundle install # Do any other automated setup that you need to do here mkalias-1.0.10/Gemfile0000644000004100000410000000013412733017277014544 0ustar www-datawww-datasource 'https://rubygems.org' # Specify your gem's dependencies in mkalias.gemspec gemspec mkalias-1.0.10/.rspec0000644000004100000410000000003712733017277014370 0ustar www-datawww-data--format documentation --color mkalias-1.0.10/mkalias.gemspec0000644000004100000410000000214212733017277016240 0ustar www-datawww-data# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'mkalias/version' Gem::Specification.new do |spec| spec.name = 'mkalias' spec.version = Mkalias::VERSION spec.authors = ['Luciano Prestes Cavalcanti'] spec.email = ['lucianopcbr@gmail.com'] spec.summary = 'A program to create bash alias' spec.description = 'MKalias is a bash alias manage, when you can just' \ ' add a command and you can add a new alias, list' \ ' the alias, show the alias command or remove the' \ ' alias.' spec.homepage = 'https://github.com/LucianoPC/mkalias' spec.license = 'Expat' spec.files = `git ls-files -z`.split("\x0").reject do |f| f.match(%r{^(test|features)/}) end spec.bindir = 'bin' spec.executables << 'mkalias' spec.require_paths = ['lib'] spec.add_development_dependency 'bundler', '~> 1.12' spec.add_development_dependency 'rake', '~> 10.0' spec.add_development_dependency 'rspec', '~> 3.0' end mkalias-1.0.10/CODE_OF_CONDUCT.md0000644000004100000410000000452512733017277016060 0ustar www-datawww-data# Contributor Code of Conduct As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery * Personal attacks * Trolling or insulting/derogatory comments * Public or private harassment * Publishing other's private information, such as physical or electronic addresses, without explicit permission * Other unethical or unprofessional conduct Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team. This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting a project maintainer at lucianopcbr@gmail.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. Maintainers are obligated to maintain confidentiality with regard to the reporter of an incident. This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.3.0, available at [http://contributor-covenant.org/version/1/3/0/][version] [homepage]: http://contributor-covenant.org [version]: http://contributor-covenant.org/version/1/3/0/mkalias-1.0.10/spec/0000755000004100000410000000000012733017277014205 5ustar www-datawww-datamkalias-1.0.10/spec/spec_helper.rb0000644000004100000410000000011512733017277017020 0ustar www-datawww-data$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) require 'mkalias' mkalias-1.0.10/spec/mkalias_spec.rb0000644000004100000410000000705412733017277017173 0ustar www-datawww-datarequire 'spec_helper' FILE_PATH = './test_bashrc'.freeze describe Mkalias do it 'has a version number' do expect(Mkalias::VERSION).not_to be nil end describe 'test Mkalias functions' do before do File.new(FILE_PATH, 'w') open(FILE_PATH, 'a') do |file| file.puts("\n") file.puts("alias cd='mkalias_cd'\n") file.puts("function mkalias_cd(){ ls -la; }\n") file.puts("\n") file.puts("alias mv='mkalias_mv'\n") file.puts("function mkalias_mv(){ touch; pwd; }\n") file.puts("\n") file.puts("alias fkd='mkalias_fkd'\n") file.puts("function mkalias_fkd(){ flake8 $(git ls-files -m) $@; }\n") end end after do File.delete(FILE_PATH) end it 'create new alias' do alias_name = 'ls' command = 'pwd' Mkalias.new_alias(alias_name, command, FILE_PATH) lines = File.readlines(FILE_PATH) expect(lines).to include("alias ls='mkalias_ls'\n") expect(lines).to include("function mkalias_ls(){ pwd $@; }\n") end it 'create new alias with args' do alias_name = 'ls' command = 'echo #1 #2' Mkalias.new_alias(alias_name, command, FILE_PATH) lines = File.readlines(FILE_PATH) expect(lines).to include("alias ls='mkalias_ls'\n") expect(lines).to include("function mkalias_ls(){ echo $1 $2; }\n") end it 'create new alias with multiple commands' do alias_name = 'ls' commands = ['pwd', 'echo a', 'cd'] Mkalias.new_alias(alias_name, commands, FILE_PATH) lines = File.readlines(FILE_PATH) expect(lines).to include "alias ls='mkalias_ls'\n" expect(lines).to include "function mkalias_ls(){ pwd; echo a; cd; }\n" end it 'dont create new alias with an existing name' do alias_name = 'cd' command = 'echo #1 #2' result = Mkalias.new_alias(alias_name, command, FILE_PATH) expect(result).to be false end it 'list all alias' do alias_names = Mkalias.list_alias(FILE_PATH) expect(alias_names).to include 'cd' expect(alias_names).to include 'mv' expect(alias_names).to include 'fkd' end it 'show alias commands' do alias_commands = Mkalias.show_alias(%w(cd mv fkd), FILE_PATH) expect(alias_commands['cd']).to include 'ls -la' expect(alias_commands['mv'][0]).to eq 'touch' expect(alias_commands['mv'][1]).to eq 'pwd' expect(alias_commands['fkd']).to include 'flake8 $(git ls-files -m) $@' end it 'dont show alias commands if alias not exists' do alias_commands = Mkalias.show_alias(['dd'], FILE_PATH) expect(alias_commands.keys).not_to include 'dd' end it 'remove alias' do removed_alias = Mkalias.remove_alias(%w(cd mv), FILE_PATH) alias_names = Mkalias.list_alias(FILE_PATH) expect(removed_alias).to include 'cd' expect(removed_alias).to include 'mv' expect(alias_names).not_to include 'cd' expect(alias_names).not_to include 'mv' end it 'add signal' do result = Mkalias.add_signal(FILE_PATH) expect(result).to be true end it 'dont add signal if already exists' do Mkalias.add_signal(FILE_PATH) result = Mkalias.add_signal(FILE_PATH) expect(result).to be false end it 'remove signal' do Mkalias.add_signal(FILE_PATH) result = Mkalias.remove_signal(FILE_PATH) expect(result).to be true end it 'dont remove signal unless already exists' do result = Mkalias.remove_signal(FILE_PATH) expect(result).to be false end end end mkalias-1.0.10/.travis.yml0000644000004100000410000000027612733017277015371 0ustar www-datawww-datasudo: false language: ruby rvm: - 2.3.1 before_install: - gem install bundler -v 1.12.3 - gem install rubocop -v 0.40.0 script: - rubocop . - bundle exec rspec spec - rake build mkalias-1.0.10/lib/0000755000004100000410000000000012733017277014021 5ustar www-datawww-datamkalias-1.0.10/lib/usage.rb0000644000004100000410000000227012733017277015453 0ustar www-datawww-data# Module with Mkalias usage options module Usage module_function def header %(Usage: mkalias [option] options: ) end def option_new %( new \t\t $ mkalias new [alias] [command 1] [command 2] ... [command n] \t\t - Create a new alias to run the commands ) end def option_list %( list \t\t $ mkalias list \t\t - List all alias ) end def option_show %( show \t\t $ mkalias show \t\t - Show commands of all alias \t\t $ mkalias show [alias 1] [alias 2] ... [alias n] \t\t - Show commands of the specified alias ) end def option_remove %( remove \t $ mkalias remove [alias 1] [alias 2] ... [alias n] \t\t - Remove the specified alias ) end def option_signals %( add_signal \t $ mkalias add_signal \t\t - Add signal to run 'source ~/.bashrc' when \t\t - add or remove an alias remove_signal $ mkalias remove_signal \t\t - Remove signal to run 'source ~/.bashrc' when \t\t - add or remove an alias ) end def attention %( Attention: To make alias with args use #. Example: $ mkalias new [alias] "echo #1 #2 #3" - Then you can use: $ [alias] arg1 arg2 arg3 ) end end mkalias-1.0.10/lib/mkalias.rb0000644000004100000410000000646312733017277016000 0ustar www-datawww-datarequire 'mkalias/version' require 'set' # Module to manage alias module Mkalias module_function SIGNAL_NAME = 'USR1'.freeze BASHRC_PATH = "#{File.expand_path('~')}/.bashrc".freeze def new_alias(alias_name, commands, file_path = BASHRC_PATH) alias_names = Mkalias.list_alias(file_path) return false if alias_names.include?(alias_name) commands = Mkalias.prepare_commands(commands) function_name = "mkalias_#{alias_name}" bash_function = "function #{function_name}(){ #{commands}; }" bash_alias = "alias #{alias_name}='#{function_name}'" open(file_path, 'a') do |file| file.puts("\n#{bash_alias}\n#{bash_function}") end true end def list_alias(file_path = BASHRC_PATH) alias_regex = /mkalias_(.*?)\(/ file_text = File.open(file_path, &:read) alias_names = file_text.scan(alias_regex).flatten alias_names end def show_alias(alias_names, file_path = BASHRC_PATH) alias_names = [alias_names] unless alias_names.is_a?(Array) alias_commands = {} alias_names.each do |alias_name| alias_commands[alias_name] = Mkalias.get_alias_command(alias_name, file_path) end alias_commands.select! { |_, value| !value.nil? } alias_commands end def remove_alias(alias_names, file_path = BASHRC_PATH) alias_names = [alias_names] unless alias_names.is_a?(Array) removed_alias = [] alias_names.each do |alias_name| removed = Mkalias.remove_one_alias(alias_name, file_path) removed_alias << alias_name if removed end removed_alias end def add_signal(file_path = BASHRC_PATH) return false if Mkalias.signal?(file_path) trap_command = "trap 'source #{file_path}' #{SIGNAL_NAME}" open(file_path, 'a') do |file| file.puts("\n") file.puts(trap_command) end true end def remove_signal(file_path = BASHRC_PATH) return false unless signal?(file_path) trap_regex = /\btrap\s'source\s(.*)\sUSR1/ lines = File.readlines(file_path).reject { |line| line =~ trap_regex } File.open(file_path, 'w') { |f| lines.each { |line| f.puts line } } true end def signal?(file_path = BASHRC_PATH) trap_regex = /\btrap\s'source\s(.*)\sUSR1/ !File.foreach(file_path).grep(trap_regex).empty? end def get_alias_command(alias_name, file_path = BASHRC_PATH) alias_names = Mkalias.list_alias(file_path) return nil unless alias_names.include?(alias_name) command_regex = /mkalias_#{alias_name}\(\)[{](.+)[;]/ file_text = File.open(file_path, &:read) commands = file_text.scan(command_regex).flatten.first commands = commands.split(';').each(&:strip!) if commands commands end def remove_one_alias(alias_name, file_path = BASHRC_PATH) alias_names = Mkalias.list_alias(file_path) return false unless alias_names.include?(alias_name) alias_regex = /\bmkalias_#{alias_name}[(']/ lines = File.readlines(file_path).reject { |line| line =~ alias_regex } File.open(file_path, 'w') { |f| lines.each { |line| f.puts line } } end def prepare_commands(commands) commands = commands.join('; ') if commands.is_a?(Array) unless commands.include?(';') || commands.include?('#') commands = "#{commands} $@" end commands = commands.tr('#', '$') commands end end mkalias-1.0.10/lib/mkalias/0000755000004100000410000000000012733017277015442 5ustar www-datawww-datamkalias-1.0.10/lib/mkalias/version.rb0000644000004100000410000000005712733017277017456 0ustar www-datawww-datamodule Mkalias VERSION = '1.0.10'.freeze end mkalias-1.0.10/.gitignore0000644000004100000410000000117312733017277015245 0ustar www-datawww-data*.gem *.rbc /.config /coverage/ /InstalledFiles /pkg/ /spec/reports/ /spec/examples.txt /test/tmp/ /test/version_tmp/ /tmp/ ## Specific to RubyMotion: .dat* .repl_history build/ ## Documentation cache and generated files: /.yardoc/ /_yardoc/ /doc/ /rdoc/ ## Environment normalization: /.bundle/ /vendor/bundle /lib/bundler/man/ # for a library or gem, you might want to ignore these files since the code is # intended to run in multiple environments; otherwise, check them in: Gemfile.lock # .ruby-version # .ruby-gemset # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: .rvmrc ## Temp files *.swp *.swo *~ mkalias-1.0.10/LICENSE0000644000004100000410000000206612733017277014264 0ustar www-datawww-dataCopyright © Luciano Prestes Expat (aka MIT) License 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. mkalias-1.0.10/ChangeLog0000644000004100000410000000106612733017277015030 0ustar www-datawww-dataThu Jun 23 14:37:39 BRT 2016 Luciano Prestes Cavalcanti * Remove bundler from runtime dependences Thu Jun 23 10:51:44 BRT 2016 Luciano Prestes Cavalcanti * Fix mkalias manpage Mon Jun 20 10:46:33 BRT 2016 Luciano Prestes Cavalcanti * Fix bug on mkalias show Fri Jun 17 16:49:50 BRT 2016 Luciano Prestes Cavalcanti * Add spec files on gemspec Fri Jun 17 15:16:40 BRT 2016 Luciano Prestes Cavalcanti * Initial Release mkalias-1.0.10/mkalias.10000644000004100000410000000223412733017277014757 0ustar www-datawww-data.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.4. .TH USAGE: "1" "June 2016" "Usage: mkalias [option]" "User Commands" .SH NAME Mkalias - Bash alias management to facilitate alias creation .SH SYNOPSIS .B mkalias [\fI\,option\/\fR] .SH DESCRIPTION options: .TP new $ mkalias new [alias] [command 1] [command 2] ... [command n] .IP \- Create a new alias to run the commands .TP list $ mkalias list .IP \- List all alias .TP show $ mkalias show \- Show commands of all alias .IP \f(CW$ mkalias show [alias 1] [alias 2] ... [alias n]\fR .IP \- Show commands of the specified alias .TP remove $ mkalias remove [alias 1] [alias 2] ... [alias n] .IP \- Remove the specified alias .TP add_signal $ mkalias add_signal .IP \- Add signal to run 'source ~/.bashrc' when .IP \- add or remove an alias .TP remove_signal $ mkalias remove_signal .IP \- Remove signal to run 'source ~/.bashrc' when .IP \- add or remove an alias .TP Attention: To make alias with args use #. Example: .IP \f(CW$ mkalias new [alias] "echo #1 #2 #3"\fR .IP \- Then you can use: $ [alias] arg1 arg2 arg3 .SH "SEE ALSO" The full documentation for .B Mkalias: .TP https://github.com/LucianoPC/mkalias mkalias-1.0.10/README.md0000644000004100000410000000510712733017277014535 0ustar www-datawww-data# Mkalias [![Build Status](https://travis-ci.org/LucianoPC/mkalias.svg?branch=master)](https://travis-ci.org/LucianoPC/mkalias) [![Code Climate](https://codeclimate.com/github/LucianoPC/mkalias/badges/gpa.svg)](https://codeclimate.com/github/LucianoPC/mkalias) [![Gem Version](https://badge.fury.io/rb/mkalias.svg)](https://badge.fury.io/rb/mkalias) MKalias is a gem to manage alias, when you can just add a command and you can add a new alias, list the alias, show the alias command or remove the alias. ## Installation Add this line to your application's Gemfile: ```ruby gem 'mkalias' ``` And then execute: $ bundle Or install it yourself as: $ gem install mkalias ## Usage run: $ mkalias [option] options: new $ mkalias new [alias] [command 1] [command 2] ... [command n] - Create a new alias to run the commands list $ mkalias list - List all alias show $ mkalias show - Show commands of all alias $ mkalias show [alias 1] [alias 2] ... [alias n] - Show commands of the specified alias remove $ mkalias remove [alias 1] [alias 2] ... [alias n] - Remove the specified alias add_signal $ mkalias add_signal - Add signal to run 'source ~/.bashrc' when - add or remove an alias remove_signal $ mkalias remove_signal" - Remove signal to run 'source ~/.bashrc' when - add or remove an alias Attention: To make alias with args use #. Example: $ mkalias new [alias] "echo #1 #2 #3" Then you can use: $ [alias] arg1 arg2 arg3 ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/LucianoPC/mkalias. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.