Merge branch 'trunk' of github.com:bugabinga/dotfiles into trunk
eab17ecac5835c3e74149fa0e95a2809798dc00b
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
- Parent 1: 059b85737ead · Showing diff
- Parent 2: a1bd167746dc · Diff against parent 2
bugabingas dorkfiles
eab17ecac5835c3e74149fa0e95a2809798dc00b
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
+59 / −0 text lines
+2 / −0 text lines
+55 / −0 text lines
# creates a backup of the given file in a temporary directory and prints the pathexport def bak [ file: path # the file to copy into a backup] { if not ($file | path exists ) { error make { msg: "The file to backup does not exist.", label: { text: "Missing its existence!", span: (metadata $file).span } } } let full_path = $file | path expand let tmpdir = mktemp --directory --tmpdir backup_XXX let backup = $tmpdir | path join ( $file | path basename ) let backup_original_path = $tmpdir | path join 'original.path' $full_path | save $backup_original_path cp --preserve [ mode timestamps ] $file $backup print $backup}# restores a backup previously made with `bak` commandexport def kab [ backup: path # a backup file to restore] { if not ($backup | path exists ) { error make { msg: "The backup file does not exist.", label: { text: "Missing its existence!", span: (metadata $backup).span } } } let backup_file = $backup | path expand if ($backup_file !~ 'backup_' ) { error make { msg: "The file does not seem to be a backup file from `bak`.", label: { text: "Are u even bak'ed up?", span: (metadata $backup).span } } } let backup_dir = $backup | path dirname let original_path_file = $backup_dir | path join 'original.path' let original_path = open --raw $original_path_file try { mv --progress --interactive --verbose $backup_file $original_path } catch { return # skip deletion } rm --trash --recursive $backup_dir}+2 / −0 text lines