win_alias 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0d18367849840c3235aa2650542dacc28a6ef85670b5dcb26fff8a963c4560e7
4
+ data.tar.gz: cb53fe0224aa1b726f1feea84379096610f64277df90b0235e721f141b14b8cd
5
+ SHA512:
6
+ metadata.gz: 44f1711bb42d603cee89d42caeca0acfb1e64f2526af8653a41a955f5da438e4e3ae9f4df4b36dfb8bc8a9ad96229c4a6a1a7b6cd3b12b952e921645086141a5
7
+ data.tar.gz: a28e2e50cc92fb775db45bf269b8f07e70a31d6a145d43604d6862c57440fc80e3dbcb85b00ae468849e4840f17f54aea55c144c902283845afa870b53029b84
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.2
5
+ before_install: gem install bundler -v 1.16.0
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at bblack@digitalglobe.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in win_alias.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 bj002440
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,89 @@
1
+ # WinAlias
2
+
3
+ WinAlias provides a simple CLI tool to add aliases to your windows environment just like Unix using your PATH environment and batch scripts. This is in very early development and is not intended to do anything more advanced than what is advertised. It is purely for convenience.
4
+
5
+ ## Installation
6
+
7
+ $ gem install win_alias
8
+
9
+ ## Usage
10
+
11
+ In order to use WinAlias, be sure to add the following path to your system or user path:
12
+
13
+ - `C:\Users\<UserName>\win-alias\bin`
14
+
15
+ Once the path is in your system you can add aliases and use them anywhere in cmd or any other Windows shell.
16
+
17
+ IMPORTANT NOTE: If you do not add the bin directory to your PATH youself, win-alias will attempt to add it the first time it runs. This may cause issues with PATHS over 1024 characters on older Windows versions. Be sure to check your PATH if you rely on the automatic adding of the bin path. Just in case, your original PATH variable will be backed up into `C:\Users\<UserName>\win-alias\path_backup.txt`
18
+
19
+ ### Add alias
20
+
21
+ You can add aliases using any of the examples shown below. If your command includes flags, use the `-c` or `--cmd` argument followed by your command in quotes to avoid collisions with the flags win-alias expects.
22
+
23
+ ```
24
+ # Alias dir to ls
25
+ win-alias ls dir
26
+
27
+ # Now run ls
28
+ ls
29
+
30
+ # Alias ll to "ls -l"
31
+ # Notice how --cmd is used to avoid win-alias treating -l as a flag to itself
32
+ win-alias ll --cmd "ls -l"
33
+
34
+ # Now run ll
35
+ ll
36
+ ```
37
+
38
+ ### Edit alias
39
+
40
+ You can also have win-alias open the generated script up into your systems text editor after it is created. This allows you to more easily generate much larger aliased scripts without having to rely entirely on passing the script in via the command line. To do this just add the __-e__ flag to the win-alias command.
41
+
42
+ Additionally it is possible to edit existing aliases easily via the CLI. To do this, use the following command: `win-alias <alias-name> -e`
43
+ NOTE: If you pass additional arguments the alias will be overwritten before being edited, so if you wish to edit only, please use -e only.
44
+
45
+ ```
46
+ # Create an alias called ll and open it in a text editor after it is created
47
+ win-alias ll "ls -lh" -e
48
+
49
+ # Open an existing alias called ll for editing.
50
+ # win-alias ll -e
51
+ ```
52
+
53
+ ### Delete alias
54
+
55
+ ```
56
+ win-alias ll -d
57
+ ```
58
+
59
+ ### List aliases
60
+
61
+ ```
62
+ win-alias -l
63
+ ```
64
+
65
+ ### Help
66
+
67
+ Run the win-alias command with no arguments to display the help menu
68
+
69
+ ```
70
+ win-alias
71
+ ```
72
+
73
+ ## Development
74
+
75
+ 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.
76
+
77
+ 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).
78
+
79
+ ## Contributing
80
+
81
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/win_alias. 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.
82
+
83
+ ## License
84
+
85
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
86
+
87
+ ## Code of Conduct
88
+
89
+ Everyone interacting in the WinAlias project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/win_alias/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "win_alias"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'win_alias/cli'
@@ -0,0 +1,3 @@
1
+ require_relative 'win_alias/version'
2
+ require_relative 'win_alias/util'
3
+ require_relative 'win_alias/alias'
@@ -0,0 +1,34 @@
1
+ module WinAlias
2
+ class Alias
3
+ include BBLib::Effortless
4
+
5
+ attr_str :name, required: true, arg_at: 0
6
+ attr_str :command, required: true, arg_at: 1
7
+ attr_bool :temp, default: false
8
+ attr_bool :echo_off, default: true
9
+
10
+ def self.delete!(name)
11
+ path = File.join(WinAlias.path, "#{name}.bat")
12
+ return true unless File.exist?(path)
13
+ FileUtils.rm(path)
14
+ !File.exist?(path)
15
+ end
16
+
17
+ def self.list
18
+ BBLib.scan_dir(WinAlias.path, '*.bat').map { |f| f.file_name(false) }.sort
19
+ end
20
+
21
+ def path
22
+ File.join(WinAlias.path, "#{name}.bat")
23
+ end
24
+
25
+ def build_command
26
+ (echo_off? ? "@ECHO OFF\n" : '') + command
27
+ end
28
+
29
+ def save
30
+ build_command.to_file(path, mode: 'w')
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,62 @@
1
+ require 'bblib'
2
+ require 'bblib/cli'
3
+
4
+ require_relative '../win_alias'
5
+
6
+ BBLib.color_logs = true
7
+ BBLib.logger.level = :debug if ARGV.include?('-v') || ARGV.include?('--verbose')
8
+ BBLib.logger.level = :fatal if ARGV.include?('-q') || ARGV.include?('--quiet')
9
+
10
+ BBLib.logger.formatter = proc do |severity, datetime, progname, msg|
11
+ msg = msg.to_s.to_color(severity) if BBLib.color_logs && severity.to_s.downcase != 'info'
12
+ if msg.is_a?(Exception)
13
+ msg = msg.inspect + "\n\t" + msg.backtrace.join("\n\t")
14
+ end
15
+ "#{msg.to_s.chomp}\n"
16
+ end
17
+
18
+ module WinAlias
19
+ parser = BBLib::OptsParser.new do |pars|
20
+ pars.usage "Usage: win-alias <alias> [command...] [options...]\n\n\tCreate an alias: win-alias <alias> [command...]\n\tEdit an alias: win-alias <alias> -e\n\tDelete an alias: win-alias <alias> -d\n"
21
+ pars.string('-c', '--cmd', '--command', desc: 'The command to alias. If not provided, all unrecognized arguments are treated as the command.')
22
+ pars.toggle('-d', '--delete', desc: 'Deletes the provided alias instead of creating one')
23
+ pars.toggle('-l', '--list', desc: 'List all known aliases')
24
+ pars.toggle('-y', '--yes-to-all', desc: 'Yes to any prompts. This is mostly useful to avoid the overwrite prompt if an alias already exists.')
25
+ pars.command(position: 0, name: :alias)
26
+ pars.toggle('-e', '--edit', desc: 'Open up the alias script in your text editor after it is created.')
27
+ pars.untoggle('--echo', desc: 'Do not disable echo in the aliased command. By default it is enabled.')
28
+ end
29
+
30
+ opts = parser.parse
31
+ add_to_path
32
+
33
+ if opts[:delete]
34
+ if Alias.delete!(opts.alias)
35
+ info "All aliases matching #{opts.alias} have been removed."
36
+ else
37
+ warn "Failed to delete #{opts.alias}. Could be a permissions issue."
38
+ end
39
+ elsif opts.list? || opts.alias == '-l' || opts.alias == '--list'
40
+ puts "\t- " + Alias.list.join("\n\t- ")
41
+ elsif opts.alias.nil? || opts.alias == '-h' || opts.alias == '--help'
42
+ puts parser.help
43
+ elsif opts.edit? && (opts.cmd.nil? || opts.cmd.empty?) && opts.arguments.empty?
44
+ BBLib::Console.edit_file(Alias.new(opts.alias, opts.cmd).path)
45
+ else
46
+
47
+ if Alias.list.include?(opts.alias) && !opts.yes_to_all?
48
+ exit(2) unless BBLib::Console.confirm?("There is already an alias named #{opts.alias}. Do you want to overwrite it?")
49
+ end
50
+
51
+ if opts.cmd && opts.cmd.empty? || opts.cmd.nil?
52
+ opts.cmd = opts.arguments.size == 1 ? opts.arguments.first : opts.arguments.map do |arg|
53
+ arg.include?(' ') ? "\"#{arg.gsub('"', '\\"')}\"" : arg
54
+ end.join(' ')
55
+ end
56
+ als = Alias.new(opts.alias, opts.cmd, echo_off: opts.echo)
57
+ if als.save
58
+ BBLib::Console.edit_file(als.path) if opts.edit?
59
+ puts BBLib::Console.colorize("Created alias for #{opts.alias}", :light_green)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,36 @@
1
+ module WinAlias
2
+ [:debug, :info, :warn, :error, :fatal].each do |severity|
3
+ define_singleton_method(severity) do |message|
4
+ BBLib.logger.send(severity, message)
5
+ end
6
+ end
7
+
8
+ def self.base_path
9
+ ENV['WIN_ALIAS_HOME'] || File.join(Dir.home, 'win_alias')
10
+ end
11
+
12
+ def self.path
13
+ File.join(base_path, 'bin')
14
+ end
15
+
16
+ def self.in_path?
17
+ ENV['PATH'].include?(path)
18
+ end
19
+
20
+ def self.add_to_path
21
+ return true if in_path?
22
+ warn("About to add win-alias/bin to PATH. A backup of your paths will be saved @ #{File.join(base_path, 'path_backup.txt')} in case something goes wrong.")
23
+ error("NOTE: It is recommdned you verify your PATH in another shell after this is run. Some versions of Windows can cause the PATH to be truncated at 1024 characters.")
24
+ backup_path_variable
25
+ ENV['PATH'] = ENV['PATH'] + ";#{path}"
26
+ `setx /M PATH "#{ENV['PATH']}"`
27
+ in_path?
28
+ end
29
+
30
+ def self.backup_path_variable
31
+ backup = File.join(base_path, 'path_backup.txt')
32
+ lines = File.exist?(backup) ? File.read(backup).split("\n") : []
33
+ lines += ENV['PATH'].split(';')
34
+ lines.uniq.join("\n").to_file(backup, mode: 'w')
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module WinAlias
2
+ VERSION = '0.1.1'.freeze
3
+ end
@@ -0,0 +1,38 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "win_alias/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "win_alias"
8
+ spec.version = WinAlias::VERSION
9
+ spec.authors = ["bblack16"]
10
+ spec.email = ["d2sm10@hotmail.com"]
11
+
12
+ spec.summary = %q{CLI to easily create aliases in a Windows environment.}
13
+ spec.description = %q{Manage simple bat scripts to easily generate aliases in Windows.}
14
+ spec.homepage = "https://github.com/bblack16/win-alias"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "bin"
30
+ spec.executables = ['win-alias']
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.16"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+
37
+ spec.add_runtime_dependency 'bblib', '~> 2.0', '>= 2.0.3'
38
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: win_alias
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - bblack16
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bblib
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 2.0.3
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '2.0'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 2.0.3
75
+ description: Manage simple bat scripts to easily generate aliases in Windows.
76
+ email:
77
+ - d2sm10@hotmail.com
78
+ executables:
79
+ - win-alias
80
+ extensions: []
81
+ extra_rdoc_files: []
82
+ files:
83
+ - ".gitignore"
84
+ - ".rspec"
85
+ - ".travis.yml"
86
+ - CODE_OF_CONDUCT.md
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - bin/console
92
+ - bin/setup
93
+ - bin/win-alias
94
+ - lib/win_alias.rb
95
+ - lib/win_alias/alias.rb
96
+ - lib/win_alias/cli.rb
97
+ - lib/win_alias/util.rb
98
+ - lib/win_alias/version.rb
99
+ - win_alias.gemspec
100
+ homepage: https://github.com/bblack16/win-alias
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.7.3
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: CLI to easily create aliases in a Windows environment.
124
+ test_files: []