Code Monkey home page Code Monkey logo

homebrew-aliases's Introduction

Homebrew Aliases

This tap allows you to alias your Homebrew commands.

Install

brew tap homebrew/aliases

Usage

This works similar to the alias command:

# add aliases
$ brew alias up='update'
$ brew alias i='install'

# print all aliases
$ brew alias

# print one alias
$ brew alias up

# use your aliases like any other command
$ brew i git

# remove an alias
$ brew unalias i

Note: Some commands are reserved and can’t be aliased (Homebrew core commands as well as alias and unalias).

Additional Features

All aliases are prefixed with brew, unless they start with ! or %:

# 'brew up' -> 'brew update'
$ brew alias up=update

# 'brew status' -> 'git status'
$ brew alias status='!git status'

Note: You may need single-quotes to prevent your shell from interpreting !, but % will work for both types.

# Use shell expansion to preserve a local variable
# 'brew git status' -> '/path/to/my/git status'
$ mygit=/path/to/my/git
$ brew alias git="% $mygit"

Aliases can include other aliases:

$ brew alias show=info
$ brew alias print=show
$ brew print git # will run 'brew info git'

Aliases can be opened in $EDITOR with the --edit flag.

# Edit alias 'brew foo'
$ brew alias foo --edit
# Assign and edit alias 'brew foo'
$ brew alias foo=bar --edit

# This works too
$ brew alias --edit foo
$ brew alias --edit foo=bar

# Open all aliases in EDITOR
$ brew alias --edit

Note: If the named alias doesn't exist it will be created.

homebrew-aliases's People

Contributors

bfontaine avatar bo98 avatar branchvincent avatar brewtestbot avatar dduugg avatar issyl0 avatar kabel avatar leoheitmannruiz avatar leonklingele avatar lylemoffitt avatar mikemcquaid avatar nandahkrishna avatar p-linnane avatar reitermarkus avatar rrotter avatar rylan12 avatar samford avatar texastoland avatar wavinflag avatar xu-cheng avatar yumitsu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

homebrew-aliases's Issues

Prefix "!" produces error

Tried to create a simple alias with the "!" prefix, like so:

bash-4.4$ brew alias toast="!echo I like toast"
bash: !echo: event not found

The standard usage seems to work though.

unalias and edit throw unreasonable errors

unalias always says the alias doesn't exist.
alias --edit always says the alias already exists (which is true, but shouldn't be an error).

$ brew alias
brew alias overwrite='info %'
brew alias i='install'
$ brew unalias overwrite
Error: 'brew overwrite' is not aliased to anything.
$ brew alias --edit overwrite
Error: 'brew overwrite' already exists. Sorry.
$ brew unalias i
Error: 'brew i' is not aliased to anything.

--help doesn’t work on aliases

$ brew install --help
brew install [--debug] [--env=std|super] [--ignore-dependencies] [--only-dependencies] [--cc=compiler] [--build-from-source] [--devel|--HEAD] [--keep-tmp] formula:
    Install formula.
[…]

$ brew alias yolo=install
$ brew yolo --help
Warning: No help text in: /usr/local/bin/brew-yolo
Example usage:
  brew search [TEXT|/REGEX/]
  brew (info|home|options) [FORMULA...]
[…]

Aliases aren't found

I have a fresh install of homebrew and homebrew-aliases on macos catalina and none of the aliases I created take effect.

$ brew --version

Homebrew 3.0.5-62-gacfe9d2
Homebrew/homebrew-core (git revision ee7e17270e; last commit 2021-03-15)
Homebrew/homebrew-cask (git revision 86545bc466; last commit 2021-03-15)

$ brew tap --debug --verbose

adoptopenjdk/openjdk
aws/tap
chrokh/tap
colindean/fonts-nonfree
homebrew/aliases
homebrew/cask
homebrew/cask-fonts
homebrew/cask-versions
homebrew/command-not-found
homebrew/core
jmespath/jmespath
minio/stable
paulfitz/data
rbenv/tap
saulpw/vd
srkomodo/tap
universal-ctags/universal-ctags

$ brew alias

brew alias upg='upgrade'
brew alias ci='cask install'
brew alias i='install'
brew alias old='outdated'
brew alias cold='outdated --cask'
brew alias cupg='cask upgrade'

$ brew old

Error: Unknown command: old

$ type -a brew

brew is /usr/local/bin/brew
brew is /usr/local/bin/brew

$ which brew

/usr/local/bin/brew

$ echo $SHELL

/usr/local/bin/fish

$ ls ~/.brew-aliases

ci cold cupg i old upg

I am not sure what the issue is, but if there is any more information I can provide to help diagnose the issue please reach out.

`brew commands` outputs `alias` command twice.

That's what I get when running brew commands after latest updates.
Screen Shot 2020-03-02 at 09 02 15

Also, brew tap-info tells:

λ brew tap-info homebrew/aliases
homebrew/aliases: unpinned, 3 commands                     <------------ 3 commands?
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-aliases (194 files, 125.6KB)
From: https://github.com/Homebrew/homebrew-aliases

Aliases are not saved into XDG_CONFIG_HOME

...as line 9 always fails.

BASE_DIR = begin
Pathname.new("~/.config/brew-aliases").realpath
rescue
Pathname.new("~/.brew-aliases").expand_path
end.freeze

Changing it to

    Pathname.new("~/.config/brew-aliases").expand_path

should fix it, but then the latter condition ("~/.brew-aliases") is never reached.

Weird output on certain aliases

Running brew alias -anything="12d" gives traceback of

/usr/local/Library/brew.rb:101:in `exit'
/usr/local/Library/brew.rb:101:in `<main>'

The alias still works, and the exit code is 0. From testing, it looks like it needs the alias to start with -, and the third character in the command needs to be a d. I have no clue why this happens...

(I found this by running brew alias -Syu="update && brew info")

Error in unalias

I just followed the readme:

❯ brew alias status='!git status'
❯ brew alias status              
brew alias status='!git status'
❯ brew unalias status       
Error: undefined method `named' for ["status"]:Array
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-aliases/cmd/unalias.rb:22:in `unalias'
/usr/local/Homebrew/Library/Homebrew/brew.rb:110:in `<main>'

editing existing aliases leads to unexpected results

homebrew-aliases seems to support editing alias files (there is the brew alias --edit command). But, some edits that result in otherwise working scripts can confuse the alias command leading to nonsensical output, useless files written to disk, and with the addition of the user deleting the symlink at $HOMEBREW_PREFIX/bin/brew-*, causes brew alias to overwrite user created alias scripts with corrupted data.

The following is shell output demonstrating all of the issues mentioned above. For the sake of brevity I didn't include the alias scripts, but they should be reproducible bit-for-bit using the brew alias and sed commands below.

I'm not saying that these exact scripts are useful, they aren't, but rather these are the minimal steps to reproduce issues I had with actual scripts I wrote.

~ $ # get a clean working state
~ $ rm -rf .brew-aliases/
~ $ ls /opt/homebrew/bin/brew-*
ls: /opt/homebrew/bin/brew-*: No such file or directory
~ $ # create aliases
~ $ brew alias hello='!echo hello world'
~ $ brew alias hello2='!echo hello again'
~ $ # edit aliases
# this edits the `#  alias:` comment at the top
~ $ sed -i '' 's/alias:.*$/better not edit this/' ~/.brew-aliases/hello
# this wraps the `echo` line in an `if` statement
~ $ sed -i '' 's/\(^echo.*$\)/if true; then\n  \1\nfi/' ~/.brew-aliases/hello2
~ $ # get checksums for reference
~ $ md5 .brew-aliases/*
MD5 (.brew-aliases/hello) = 5cf77855dae72c39996d8519b562cd39
MD5 (.brew-aliases/hello2) = afc0805389b434f0526959e94937370e
~ $ brew alias
brew alias # better not edit this='!echo hello world'
brew alias hello2='!if true; then'
~ $ # that output is odd, but the md5 is okay
~ $ # but there is another file?
~ $ md5 .brew-aliases/*
MD5 (.brew-aliases/__better_not_edit_this) = 17194e87812aac6f4e5be6cb8ec95d6c
MD5 (.brew-aliases/hello) = 5cf77855dae72c39996d8519b562cd39
MD5 (.brew-aliases/hello2) = afc0805389b434f0526959e94937370e
~ $ ls -1 /opt/homebrew/bin/brew-*
/opt/homebrew/bin/brew-# better not edit this
/opt/homebrew/bin/brew-hello
/opt/homebrew/bin/brew-hello2
~ $ # remove the odd file and all the symlinks
~ $ rm /opt/homebrew/bin/brew-*; rm ~/.brew-aliases/__better_not_edit_this
~ $ # run alias command again to regen symlinks
~ $ brew alias
brew alias # better not edit this='!echo hello world'
brew alias hello2='!if true; then'
~ $ md5 .brew-aliases/*
MD5 (.brew-aliases/__better_not_edit_this) = 17194e87812aac6f4e5be6cb8ec95d6c
MD5 (.brew-aliases/hello) = 5cf77855dae72c39996d8519b562cd39
MD5 (.brew-aliases/hello2) = 05e54836d8513b4d67ddc757b6734504
~ $ # ^ recreated the bad file, and now hello2 is corrupted

It's pretty reasonable if these types of edits aren't supported, but brew alias should fail a little more gracefully if it can't parse a script. I found all of this by accident, and in one case was lucky that my dotfiles are in a git repo.

brew alias reports deprecated call

General troubleshooting steps

Description of issue

brew tap "homebrew/aliases"
brew alias all='update;brew upgrade;brew cask upgrade;brew cleanup;brew cask cleanup;brew doctor'

Command works as expected, creating the appropriate alias, with no functional issue. But, the command returns the following:

Warning: Calling <<-EOS.undent is deprecated!
Use <<~EOS instead.
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-aliases/cmd/brew-alias.rb:75:in `write'
Please report this to the homebrew/aliases tap!

Warning: Calling <<-EOS.undent is deprecated!
Use <<~EOS instead.
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-aliases/cmd/brew-alias.rb:95:in `block in write'
Please report this to the homebrew/aliases tap!

Output of your command with --verbose --debug

/usr/local/Homebrew/Library/Homebrew/brew.rb:107:in `exit'
/usr/local/Homebrew/Library/Homebrew/brew.rb:107:in `<main>'

Output of brew cask doctor

Your system is ready to brew.

Save in XDG_CONFIG_HOME

I understand the backwards compatibility issue. It'd be nice to at least be able to configure the directory. Generally I'd expect it in .config/brew-aliases.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.