summaryrefslogtreecommitdiff
path: root/newscript
blob: ef450a59aa578f376c5d65745b655791d7caed9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/sh

newscript ()
{
    local name=$1
    cd ~/.scripts && touch "$name" && printf "#!/bin/sh\n\n" > "$name" && vim +2 "$name"
    local linecount=$(wc -l < $HOME/.scripts/$name)
    if [ "$linecount" -lt 2 ]; then
        rm -f "$HOME/.scripts/$name"
    else
        chmod +x "$name" && cd -
    fi
}

if [ $# -ne 1 ]; then
    echo "Usage: newscript <script-name>"
    exit 1
fi

newscript $1
exit 0