DEV Community

0xkoji
0xkoji

Posted on • Edited on

Let's Create Own Simple Command 001

I'm lazy so I didn't make a gif file..., but you can see what the command I made could do.

~/Desktop/dev ls                                                            
~/Desktop/dev mkdird dev.to                                                 
~/Desktop/dev ls                                                            

dev.to_0805_2106
Enter fullscreen mode Exit fullscreen mode

name: mkdird

arg: string

function: make a folder which names arg_date

First, I tried to add a command to .zshrc as an alias, but it didn't work well since I could not pass arg to the command. Then switched creating .sh file and create a new alias.

Step 1 Create bash/zsh file

$ cd
$ mkdir .sh
$ vim mkdird.sh
Enter fullscreen mode Exit fullscreen mode
#!/usr/bin/env zsh
# create a folder --> arg_date
mkdir $1`date '+_%m%d_%H%M'`
Enter fullscreen mode Exit fullscreen mode

Step 2 Add a new alias

.zshrc

alias mkdird="~/.sh/mkdird.sh"
Enter fullscreen mode Exit fullscreen mode

Step 3 Test

test

$ mkdird dev.to

dev.to_0805_2115
Enter fullscreen mode Exit fullscreen mode

Top comments (0)