diff options
author | William Carroll <wpcarro@gmail.com> | 2019-12-22T21·32+0000 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2019-12-24T15·21+0000 |
commit | 90955a3c021a070a2a09e9b260d9d4e670c9a304 (patch) | |
tree | 5a3b1bb7a1f6578bf48123a0b7b34438f6cefffc /configs | |
parent | 82717e3f22432644756cb737ce8ee50b74e938de (diff) |
Support ensure_{file,dir} in zsh
Support functions for ensuring the existence of directories and files. These functions represent the type of small ergonomic wins that I believe libraries should support.
Diffstat (limited to 'configs')
-rw-r--r-- | configs/shared/functions.zsh | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/configs/shared/functions.zsh b/configs/shared/functions.zsh index cae434274e3c..9f1e3a77e9d0 100644 --- a/configs/shared/functions.zsh +++ b/configs/shared/functions.zsh @@ -85,6 +85,19 @@ compliments() { # Filesystem operations ################################################################################ +ensure_dir() { + # Ensures that the directory and its children exist. + # Usage: ensure_dir <path-to-dir> + mkdir -p $1 +} + +ensure_file() { + # Ensures that the file and the path to that file exist. + # Usage: ensure_dir <path-to-file> + # depends ensure_dir + ensure_dir $(dirname $1) && touch $1 +} + tar_dir() { # Tars dir as dir.tar. Removes dir. # compliments untar_dir @@ -204,11 +217,12 @@ wallpaper() { dotfilify() { # Moves a regular, non-symlinked file into my dotfiles. # compliments undotfilify + # depends ensure_dir local original_path=$(realpath $1) - # Trim $HOME prefix - local dotfile_path="${DOTFILES#$HOME/}/configs/shared/${original_path#$HOME/}" - - mv $original_path $dotfile_path && ln --force -s $dotfile_path $original_path + local dotfile_path="${DOTFILES}/configs/shared/${original_path#$HOME/}" + ensure_dir $(dirname $dotfile_path) && \ + mv $original_path $dotfile_path && \ + ln --force -s $dotfile_path $original_path } # TODO: Write more robust, tested dotfile manager application in Elisp. |