-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappend
executable file
·35 lines (31 loc) · 847 Bytes
/
append
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
file=$HOME'/.bashrc'
line=$(grep -rn -w 'alias '$1 $file | cut -d : -f 1)
exist=$(grep -w 'alias '$1 $file)
command="${@:2}"
alias=$1
if [ -z $1 ]
then
echo -e "\e[31mformat is \e[33;1m<alias> <command>\e[0m"
else
if [ -z $line ]
then
echo -e '\e[32mRunning "'$alias'" will call "'$command'"\e[0m'
echo 'alias' $alias'="'$command'"' >>~/.bashrc
exec bash
else
echo $1 "currently calls:"
echo $exist | grep -o '".*"' | tr -d '"'
echo "would you like to overwrite with" $command "? (y/n)"
read overwrite
if [ $overwrite = y ]
then
sed -i.bak -e $line'd' $file
echo 'Running "'$alias'" will call "'$command'"'
echo 'alias' $alias'="'$command'"' >>~/.bashrc
exec bash
else
echo 'Running "'$alias'" will still call "'$exist | grep -o '".*"' | tr -d '"''"'
fi
fi
fi