Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI

on:
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install ShellCheck
run: sudo apt-get install -y shellcheck

- name: Run ShellCheck
run: shellcheck aliasme.sh test/*.sh

- name: Run Tests
run: make test
2 changes: 0 additions & 2 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# aliasme
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/dc29953069bf43438f4abac2629e4b5a)](https://app.codacy.com/app/Jintin/aliasme?utm_source=github.com&utm_medium=referral&utm_content=Jintin/aliasme&utm_campaign=badger)
[![Build Status](https://travis-ci.org/Jintin/aliasme.svg?branch=master)](https://travis-ci.org/Jintin/aliasme)
[![CI](https://github.com/Jintin/aliasme/actions/workflows/ci.yml/badge.svg)](https://github.com/Jintin/aliasme/actions/workflows/ci.yml)
[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/alebcay/awesome-shell)

A shell script to organize your alias in command line.
Expand Down
84 changes: 43 additions & 41 deletions aliasme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@

_list() {

if [ -s ~/.aliasme/cmd ];then
while read name
if [ -s "$HOME/.aliasme/cmd" ];then
while read -r name
do
read value
if ! read -r value; then break; fi
echo "$name : $value"
done < ~/.aliasme/cmd
done < "$HOME/.aliasme/cmd"
fi
}

_add() {
#read name
name=$1
if [ -z $1 ]; then
read -ep "Input name to add:" name
if [ -z "$1" ]; then
read -rep "Input name to add:" name
fi

#read path
cmd="$2"
if [ -z "$2" ]; then
read -ep "Input cmd to add:" cmd
read -rep "Input cmd to add:" cmd
fi

echo $name >> ~/.aliasme/cmd
echo $cmd >> ~/.aliasme/cmd
echo "$name" >> "$HOME/.aliasme/cmd"
echo "$cmd" >> "$HOME/.aliasme/cmd"
echo "add: $name -> $cmd"

_autocomplete
Expand All @@ -34,36 +34,36 @@ _add() {
_remove() {
#read name
name=$1
if [ -z $1 ]; then
if [ -z "$1" ]; then
read -pr "Input name to remove:" name
fi

# read and replace file
if [ -s ~/.aliasme/cmd ];then
touch ~/.aliasme/cmdtemp
while read line
if [ -s "$HOME/.aliasme/cmd" ];then
touch "$HOME/.aliasme/cmdtemp"
while read -r line
do
if [ "$line" = "$name" ]; then
read line #skip one more line
read -r _ #skip one more line
echo "remove $name"
else
echo $line >> ~/.aliasme/cmdtemp
echo "$line" >> "$HOME/.aliasme/cmdtemp"
fi
done < ~/.aliasme/cmd
mv ~/.aliasme/cmdtemp ~/.aliasme/cmd
done < "$HOME/.aliasme/cmd"
mv "$HOME/.aliasme/cmdtemp" "$HOME/.aliasme/cmd"
fi
_autocomplete
}

_excute() {
if [ -s ~/.aliasme/cmd ];then
while read -u9 line; do
if [ -s "$HOME/.aliasme/cmd" ];then
while read -u9 -r line; do
if [ "$1" = "$line" ]; then
read -u9 line
eval $line
read -u9 -r line
eval "$line"
return 0
fi
done 9< ~/.aliasme/cmd
done 9< "$HOME/.aliasme/cmd"
fi
return 1
}
Expand All @@ -75,29 +75,31 @@ _bashauto()
cur="${COMP_WORDS[COMP_CWORD]}"

opts=""
if [ -s ~/.aliasme/cmd ];then
while read line
if [ -s "$HOME/.aliasme/cmd" ];then
while read -r line
do
opts+=" $line"
read line
done < ~/.aliasme/cmd
read -r _
done < "$HOME/.aliasme/cmd"
fi
COMPREPLY=( $(compgen -W "${opts}" ${cur}) )
# shellcheck disable=SC2207
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
}

_autocomplete()
{
if [ $ZSH_VERSION ]; then
if [ -n "$ZSH_VERSION" ]; then
# zsh
opts=""
if [ -s ~/.aliasme/cmd ];then
while read line
if [ -s "$HOME/.aliasme/cmd" ];then
while read -r line
do
opts+="$line "
read line
done < ~/.aliasme/cmd
read -r _
done < "$HOME/.aliasme/cmd"
fi
# shellcheck disable=SC2154
compctl -k "($opts)" al
else
# bash
Expand All @@ -108,26 +110,26 @@ _autocomplete()
_autocomplete

al(){
if [ ! -z $1 ]; then
if [ $1 = "ls" ]; then
if [ -n "$1" ]; then
if [ "$1" = "ls" ]; then
_list
elif [ $1 = "add" ]; then
_add $2 "$3"
elif [ $1 = "rm" ]; then
_remove $2
elif [ $1 = "-h" ]; then
elif [ "$1" = "add" ]; then
_add "$2" "$3"
elif [ "$1" = "rm" ]; then
_remove "$2"
elif [ "$1" = "-h" ]; then
echo "Usage:"
echo "al add [name] [command] # add alias command with name"
echo "al rm [name] # remove alias by name"
echo "al ls # alias list"
echo "al [name] # execute alias associate with [name]"
echo "al -v # version information"
echo "al -h # help"
elif [ $1 = "-v" ]; then
elif [ "$1" = "-v" ]; then
echo "aliasme 3.0.0"
echo "visit https://github.com/Jintin/aliasme for more information"
else
if ! _excute $1 ; then
if ! _excute "$1" ; then
echo "not found"
fi
fi
Expand Down
14 changes: 6 additions & 8 deletions test/aliastest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@ testInit() {

testAlias() {

path_alias=$(pwd)

name1=testaaa
cmd1=cmdaaa
testAdd $name1 $cmd1
testAdd "$name1" "$cmd1"

name2=testbbb
cmd2=cmdbbb
testAdd $name2 $cmd2
testAdd "$name2" "$cmd2"

testRemove $name1
testRemove $name2
testRemove "$name1"
testRemove "$name2"
}

testAdd() {
_add $1 $2
_add "$1" "$2"
if [[ $(_list) = *"$1 : $2"* ]]; then
log_success "path test success"
else
Expand All @@ -35,7 +33,7 @@ testAdd() {
}

testRemove() {
_remove $1
_remove "$1"
if [[ $(_list) = *"$1"* ]]; then
log_failure "remove test failure"
else
Expand Down
16 changes: 12 additions & 4 deletions test/assert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ assert_eq() {
if [ "$expected" == "$actual" ]; then
return 0
else
[ "${#msg}" -gt 0 ] && log_failure "$expected == $actual :: $msg" || true
if [ "${#msg}" -gt 0 ]; then
log_failure "$expected == $actual :: $msg"
fi
return 1
fi
}
Expand All @@ -67,7 +69,9 @@ assert_not_eq() {
if [ ! "$expected" == "$actual" ]; then
return 0
else
[ "${#msg}" -gt 0 ] && log_failure "$expected != $actual :: $msg" || true
if [ "${#msg}" -gt 0 ]; then
log_failure "$expected != $actual :: $msg"
fi
return 1
fi
}
Expand Down Expand Up @@ -128,7 +132,9 @@ assert_array_eq() {
done

if [ "$return_code" == 1 ]; then
[ "${#msg}" -gt 0 ] && log_failure "(${expected[*]}) != (${actual[*]}) :: $msg" || true
if [ "${#msg}" -gt 0 ]; then
log_failure "(${expected[*]}) != (${actual[*]}) :: $msg"
fi
fi

return "$return_code"
Expand Down Expand Up @@ -159,7 +165,9 @@ assert_array_not_eq() {
done

if [ "$return_code" == 1 ]; then
[ "${#msg}" -gt 0 ] && log_failure "(${expected[*]}) == (${actual[*]}) :: $msg" || true
if [ "${#msg}" -gt 0 ]; then
log_failure "(${expected[*]}) == (${actual[*]}) :: $msg"
fi
fi

return "$return_code"
Expand Down
Loading