├── tests ├── _output │ └── .gitkeep ├── _support │ └── bootstrap └── print-alias.zunit ├── .gitattributes ├── images ├── demo.png └── configuration.png ├── .zunit.yml ├── .gitignore ├── .github └── workflows │ └── zsh.yml ├── LICENSE ├── print-alias.plugin.zsh └── README.md /tests/_output/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/_support/bootstrap: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env zsh 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | images/** filter=lfs diff=lfs merge=lfs -text 2 | -------------------------------------------------------------------------------- /images/demo.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:13f230b0dfc20da1925d2dba3442cfb948353732a6dc31a6a891a38b6dab24e2 3 | size 43197 4 | -------------------------------------------------------------------------------- /images/configuration.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:e5ab3085e4af1c2fa51b6acfa4577beaff8205947d055a6cd8eb89dae72b79d4 3 | size 18709 4 | -------------------------------------------------------------------------------- /.zunit.yml: -------------------------------------------------------------------------------- 1 | tap: false 2 | directories: 3 | tests: tests 4 | output: tests/_output 5 | support: tests/_support 6 | time_limit: 0 7 | fail_fast: false 8 | allow_risky: false 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IntelliJ 2 | .idea/ 3 | 4 | # Vim swap files 5 | [._]*.s[a-v][a-z] 6 | !*.svg # comment out if you don't need vector files 7 | [._]*.sw[a-p] 8 | [._]s[a-rt-v][a-z] 9 | [._]ss[a-gi-z] 10 | [._]sw[a-p] 11 | 12 | # ZUnit output 13 | tests/_output/output.txt 14 | -------------------------------------------------------------------------------- /tests/print-alias.zunit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env zunit 2 | @setup { 3 | load ../print-alias.plugin.zsh 4 | bold="\e[1m" 5 | faint="\e[2m" 6 | reset="\e[0m" 7 | PRINT_ALIAS_PREFIX='> ' 8 | PRINT_ALIAS_FORMAT=$bold 9 | PRINT_NON_ALIAS_FORMAT=$faint 10 | } 11 | 12 | @test 'Formats output based from environment variables' { 13 | alias foo=bar 14 | export BUFFER='foo bar' 15 | run _print-alias 16 | assert ${output:1} same_as "> ${bold}bar${reset} ${faint}bar${reset}" 17 | } 18 | -------------------------------------------------------------------------------- /.github/workflows/zsh.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | on: 3 | - push 4 | jobs: 5 | build: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v2 9 | - name: Install Zsh 10 | run: sudo apt-get update && sudo apt-get install zsh 11 | - name: Install Revolver 12 | run: | 13 | git clone https://github.com/molovo/revolver /tmp/revolver 14 | chmod +x /tmp/revolver/revolver 15 | sudo mv /tmp/revolver/revolver /usr/local/bin 16 | - name: Install ZUnit 17 | run: | 18 | git clone https://github.com/zunit-zsh/zunit /tmp/zunit 19 | pushd /tmp/zunit 20 | ./build.zsh 21 | chmod +x ./zunit 22 | sudo mv ./zunit /usr/local/bin 23 | popd 24 | - name: Run tests 25 | run: zunit --output-text 26 | - name: Upload code coverage 27 | run: 'bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }} -f tests/_output/output.txt' 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Bryan McKelvey 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 all 13 | 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /print-alias.plugin.zsh: -------------------------------------------------------------------------------- 1 | _print-alias () { 2 | # Constants 3 | local -r PREFIX=${PRINT_ALIAS_PREFIX:-} 4 | local -r ALIAS_FORMAT=${PRINT_ALIAS_FORMAT:-$'\e[36m'} 5 | local -r NON_ALIAS_FORMAT=${PRINT_NON_ALIAS_FORMAT:-$'\e[2m'} 6 | local -r RESET_COLORS=$'\e[0m' 7 | local -r IGNORE_ALIASES=(${PRINT_ALIAS_IGNORE_ALIASES:-}) 8 | local -r IGNORE_REDEFINED_COMMANDS=${PRINT_ALIAS_IGNORE_REDEFINED_COMMANDS:-'false'} 9 | 10 | local -a words 11 | words=( ${(z)BUFFER} ) 12 | 13 | local -r first_word=${words[1]} 14 | if [[ ${IGNORE_ALIASES[(ie)$first_word]} -le ${#IGNORE_ALIASES} ]]; then 15 | return 16 | fi 17 | 18 | if [[ "$(whence -w $first_word 2>/dev/null)" == "${first_word}: alias" ]]; then 19 | shift words 20 | local -r aliased_command=($(whence $first_word)) 21 | if [[ $IGNORE_REDEFINED_COMMANDS == 'true' ]]; then 22 | if [[ $first_word == ${aliased_command[1]} ]]; then 23 | return 24 | fi 25 | fi 26 | echo -nE $'\n'"${PREFIX}${ALIAS_FORMAT}${aliased_command}${RESET_COLORS}" 27 | for word in $words; do 28 | echo -nE " ${NON_ALIAS_FORMAT}${word}${RESET_COLORS}" 29 | done 30 | fi 31 | } 32 | 33 | zle -N accept-line _print-alias-accept-line 34 | _print-alias-accept-line () { 35 | emulate -L zsh 36 | _print-alias 37 | zle .accept-line 38 | } 39 | 40 | zle -N accept-line _print-alias-accept-line 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | print-alias 2 | =========== 3 | 4 | ![Test](https://github.com/brymck/print-alias/workflows/Test/badge.svg) 5 | [![codecov](https://codecov.io/gh/brymck/print-alias/branch/master/graph/badge.svg)](https://codecov.io/gh/brymck/print-alias) 6 | 7 | This prints commands with aliases expanded whenever you use an alias at the command line. 8 | 9 | demo 10 | 11 | Usage 12 | ----- 13 | 14 | With [zplug](https://github.com/zplug/zplug), add the following to your `~/.zshrc`: 15 | 16 | ```zsh 17 | zplug "brymck/print-alias" 18 | ``` 19 | 20 | You can also use [Antigen](https://github.com/zsh-users/antigen): 21 | 22 | ```zsh 23 | antigen bundle brymck/print-alias 24 | ``` 25 | 26 | And lastly, if you want to `source` it manually, you can also clone this repo and use: 27 | 28 | ```zsh 29 | source path/to/print-alias.plugin.zsh 30 | ``` 31 | 32 | Configuration 33 | ------------- 34 | 35 | You can change the line prefix as well as the format of expanded aliases and non-aliases. 36 | You can exclude some specific aliases to be displayed. 37 | You may as well prevent any command which has been redefined by an alias to be displayed (aliases such as `alias grep='grep --colour'` or `alias ls='ls -aF'`) 38 | 39 | ```zsh 40 | export PRINT_ALIAS_PREFIX=' ╰─> ' 41 | export PRINT_ALIAS_FORMAT=$'\e[1m' 42 | export PRINT_NON_ALIAS_FORMAT=$'\e[0m' 43 | 44 | export PRINT_ALIAS_IGNORE_REDEFINED_COMMANDS=true 45 | export PRINT_ALIAS_IGNORE_ALIASES=(my_alias my_other_alias) 46 | 47 | zplug "brymck/print-alias" 48 | ``` 49 | 50 | The above will result in output such as the second line here: 51 | 52 | configuration 53 | --------------------------------------------------------------------------------