From aa4ec8c3dc07a19773c5d240f6c040ee9c7e737e Mon Sep 17 00:00:00 2001 From: mananapr Date: Sat, 2 Feb 2019 19:30:34 +0530 Subject: [PATCH] Added user scripts for archiving files and extracting archives --- cf.c | 1 + user_scripts/README.md | 6 ++++++ user_scripts/archive | 3 +++ user_scripts/extract | 20 ++++++++++++++++++++ 4 files changed, 30 insertions(+) create mode 100755 user_scripts/archive create mode 100755 user_scripts/extract diff --git a/cf.c b/cf.c index 89aaa5b..02f3180 100644 --- a/cf.c +++ b/cf.c @@ -2075,6 +2075,7 @@ int main(int argc, char* argv[]) pid = fork(); if( pid == 0 ) { + chdir(dir); execl(temp_dir, scripts[option], buf, (char *)0); exit(1); } diff --git a/user_scripts/README.md b/user_scripts/README.md index 36078aa..dd5481d 100644 --- a/user_scripts/README.md +++ b/user_scripts/README.md @@ -3,3 +3,9 @@ This directory contains some example scripts you can use with `cfiles`. ### setwal Uses [wal](https://github.com/dylanaraps/pywal) on selection to set image as wallpaper and generate a suitable colorscheme + +### archive +Creates a zip archive of selected files and stores it as `archive.zip` in the current directory. Requires `zip` to work. + +### extract +Extracts an archive of any format using respective utilities diff --git a/user_scripts/archive b/user_scripts/archive new file mode 100755 index 0000000..79131bb --- /dev/null +++ b/user_scripts/archive @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +zip -r archive -@ < ~/.cache/cfiles/clipboard diff --git a/user_scripts/extract b/user_scripts/extract new file mode 100755 index 0000000..7d91d77 --- /dev/null +++ b/user_scripts/extract @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +if [ -f $1 ] ; then + case $1 in + *.tar.bz2) tar xjf $1 ;; + *.tar.gz) tar xzf $1 ;; + *.bz2) bunzip2 $1 ;; + *.rar) 7z x $1 ;; + *.gz) gunzip $1 ;; + *.tar) tar xf $1 ;; + *.tbz2) tar xjf $1 ;; + *.tgz) tar xzf $1 ;; + *.zip) unzip $1 ;; + *.Z) uncompress $1 ;; + *.7z) 7z x $1 ;; + *) echo "'$1' cannot be extracted via extract()" ;; + esac + else + echo "'$1' is not a valid file" + fi