pyratelog

personal blog
git clone git://git.pyratebeard.net/pyratelog.git
Log | Files | Refs | README

20240425-all_for_change.md (1371B)


      1 How many times do you use the `ls` and `cd` commands on GNU/Linux systems?  I imagine it is quite a lot.
      2 
      3 I [briefly mentioned][1] my `chpwd_auto_cd` Zsh function, which will auto run the `ls` command when I `cd` into a directory.
      4 
      5 Sometimes it is also useful to auto run `cd`.
      6 
      7 A lot of the time when I create a new directory the first think I do is change into it, so I use this `mkcd` function to combine the two commands
      8 ```
      9 mkcd() {
     10      mkdir -p "$1" && \
     11        cd "$1"
     12 }
     13 ```
     14 
     15 Another common use of `cd` is when I have cloned a Git repository.  So I have combined these into `gcl`
     16 ```
     17 gcl() {
     18     git clone "${@}"
     19     test -n "${2}" && _dir=${2} || _dir=${1##*/}
     20     cd ${_dir%.git}
     21 }
     22 ```
     23 
     24 This function is a little more complex than `mkcd` as (remote) Git repositories have a URL which we don't want.  I use the special variable `$@` for the `git clone` command so it captures if I specify where to clone the repo, e.g.
     25 ```
     26 git clone git://git.pyratebeard.net/dotfiles.git /tmp/dotfiles
     27 ```
     28 
     29 If there is a second variable I set the `_dir` variable to it, otherwise I take everything after the final slash (`/`) of the URL.  For example, the repo URL _git://git.pyratebeard.net/dotfiles.git_ would give me a variable of `dotfiles.git`
     30 
     31 Then I can change to the new directory, ignoring `.git` from the repo name if it exists.
     32 
     33 [1]: 20231204-dot_matrix.html#epithet