Add extract.sh script

Also move preview script to ~/.local/bin and rename to preview.sh
This commit is contained in:
Hoang Nguyen 2024-03-14 00:00:00 +07:00
parent e5c33e7d01
commit ad08375db7
Signed by: folliehiyuki
GPG Key ID: B0567C20730E9B11
9 changed files with 107 additions and 32 deletions

View File

@ -1,3 +1,3 @@
function fish_greeting
not status is-login; and "$XDG_BIN_HOME/bunny"
not status is-login; and "$XDG_BIN_HOME/bunny.sh"
end

View File

@ -75,6 +75,7 @@ https://www.youtube.com/feeds/videos.xml?channel_id=UCEBb1b_L6zDS3xTUrIALZOw "~M
https://www.youtube.com/feeds/videos.xml?channel_id=UCcabW7890RKJzL968QWEykA "~Havard CS50" youtube
https://www.youtube.com/feeds/videos.xml?channel_id=UC8butISFwT-Wl7EV0hUK0BQ "~freeCodeCamp.org" youtube
https://www.youtube.com/feeds/videos.xml?channel_id=UCDiFRMQWpcp8_KD4vwIVicw "~Emergency Awesome" youtube
https://www.youtube.com/feeds/videos.xml?channel_id=UCjQK8kV4ik7p_605z8nTEgw "~Residual Entropy" youtube
=======Podcasts========
https://tuxdigital.com/feed/thisweekinlinux-mp3 "~This week in Linux" podcast
https://www.arresteddevops.com/episode/index.xml "~Arrested DevOps" podcast

View File

@ -16,7 +16,7 @@ alias cargo 'cargo auditable'
# neovim
abbr v nvim
abbr vv 'fzf --prompt "Edit files: " --preview "{{ xdg_dir.libexec_dir }}/preview {} 2>/dev/null" --bind "enter:become(nvim {+})"'
abbr vv 'fzf --prompt "Edit files: " --preview "{{ xdg_dir.bin_home }}/preview.sh {} 2>/dev/null" --bind "enter:become(nvim {+})"'
# emacs
abbr e 'emacs -nw'

View File

@ -163,7 +163,7 @@ set -gx FZF_DEFAULT_OPTS "--multi --layout=reverse --inline-info --cycle --separ
--color separator:{{ colors.highlight }},label:{{ colors.white2 }},border:{{ colors.highlight }}"
{% endif %}
set -gx FZF_DEFAULT_COMMAND "fd --type f --follow --hidden --exclude .git --color never"
set -gx FZF_CTRL_T_OPTS "--no-height --preview '{{ xdg_dir.libexec_dir }}/preview {} \$FZF_PREVIEW_COLUMNS \$FZF_PREVIEW_LINES 2>/dev/null'"
set -gx FZF_CTRL_T_OPTS "--no-height --preview '{{ xdg_dir.bin_home }}/preview.sh {} \$FZF_PREVIEW_COLUMNS \$FZF_PREVIEW_LINES 2>/dev/null'"
set -gx FZF_CTRL_T_COMMAND "fd . \$dir --follow --hidden --exclude .git --color never"
set -gx FZF_ALT_C_OPTS "--preview 'lsd -1FAL --group-dirs first --icon always --color always {} 2>/dev/null'"
set -gx FZF_ALT_C_COMMAND "fd --type d --follow --hidden --exclude .git --color never"

View File

@ -133,17 +133,18 @@ set findprg='fd --follow --hidden --exclude .git --color never %p %s'
command! df df -h %m 2> /dev/null
command! diff nvim -d %f %F
command! gzip tar -cvzf %a %f
command! zstd tar --zstd -cvf %a %f
command! xz bsdtar -cvJf %a %f
command! extract bsdtar -xvf %c
command! extract !{{ xdg_dir.bin_home }}/extract.sh %f
command! shred shred -fu %f
command! run !! ./%f
command! run !!./%f
command! vgrep nvim "+grep %a"
command! reload :write | restart
command! exif exiftool -all= -overwrite_original %f
" fzf file
command! FZFfile : set noquickview
\| let $FZF_RES = term('fzf --prompt "File: " --no-multi --preview "{{ xdg_dir.libexec_dir }}/preview {} \$FZF_PREVIEW_COLUMNS \$FZF_PREVIEW_LINES 2>/dev/null" 2>&0')
\| let $FZF_RES = term('fzf --prompt "File: " --no-multi --preview "{{ xdg_dir.bin_home }}/preview.sh {} \$FZF_PREVIEW_COLUMNS \$FZF_PREVIEW_LINES 2>/dev/null" 2>&0')
\| if $FZF_RES != ''
\| execute 'goto' fnameescape($FZF_RES)
\| endif
@ -312,7 +313,7 @@ filetype *.mbox aerc %f
" ------------------------------------------------------------------------------
{% set preview_cmd = xdg_dir.libexec_dir ~ '/preview %c:p %pw %ph' -%}
{% set preview_cmd = xdg_dir.bin_home ~ '/preview.sh %c:p %pw %ph' -%}
" Overwrite the image previewer
fileviewer <image/vnd.djvu,image/x-djvu> {{ preview_cmd }} 2>/dev/null

View File

@ -0,0 +1,63 @@
#!/bin/bash
# Require at least 1 argument
if [ $# -lt 1 ]; then
echo "Require at least 1 argument."
exit 1
fi
extract() {
local file="$1"
local mimetype="$(file --dereference --brief --mime-type -- "$file")"
local filename="$(basename "$file")"
if [[ $filename == @(*.tar.@(zst|gz|lz|lzma|lzo|xz|Z)|*.tb2|*.tz2|*.tbz|*.tbz2|*.taz|*.tgz|*.tlz|*.txz|*.tZ|*.taZ|*.tzst) ]] || [[ $mimetype == @(application/x-?(g)tar*|application/*-compressed-tar) ]]; then
tar -xf "$file" || bsdtar -xf "$file"
return
fi
if [[ $mimetype == application/zstd ]]; then
zstd -d "$file"; return
fi
if [[ $mimetype == @(application/x-xz*|application/*-xz-compressed) ]]; then
xz -kd "$file" || bsdtar -xf "$file"
return
fi
if [[ $mimetype == @(application/vnd.rar|application/vnd.comicbook-rar|application/x-rar*) ]]; then
unrar x -p- -- "$file" || bsdtar -xf "$file"
return
fi
if [[ $mimetype == application/x-7z-compressed ]]; then
7z x -p -- "$file" || bsdtar -xf "$file"
return
fi
if [[ $mimetype == @(application/vnd.efi.iso|application/x-*-rom|application/x-compressed-iso|application/x*-iso?(9660)-?(app)image) ]]; then
isoinfo -X -i "$file" || bsdtar -xf "$file"
return
fi
if [[ $mimetype == application/x-cpio* ]]; then
cpio -iF "$file" || bsdtar -xf "$file"
return
fi
if [[ $mimetype == application/?(x-)gzip ]]; then
bsdtar -xf "$file" || gzip -d "$file"
return
fi
if [[ $mimetype == @(application/vnd.ms-cab-compressed|application/x-archive|application/?(x-)bzip*|application/x-lzma|application/x-lzip|application/x-lha|application/x-lzh-compressed|application/x-lhz|application/x-lzop|application/x-lz4|application/x-lrzip) ]]; then
bsdtar -xf "$file"; return
fi
echo "File $file with mimetype $mimetype is not supported."
return 1
}
for file in "$@"; do
extract "$file" || exit 1
done

View File

@ -21,31 +21,36 @@
recursive: true
delete: false
- name: Copy templates to ~/.local/libexec/wayland
- name: Copy script templates
template:
src: '{{ item }}.j2'
dest: '~/.local/libexec/wayland/{{ item }}'
src: '{{ item.name }}.j2'
dest: '{{ item.dest }}'
mode: '755'
loop:
- bukumenu
- calcmenu
- clipboard
- dismiss_notify
- launch_wallpaper
- mangamenu
- musicmenu
- notifymenu
- screenshot
- searchmenu
- sway_window
- name: Copy templates to ~/.local/libexec
template:
src: '{{ item }}.j2'
dest: ~/.local/libexec/{{ item }}
mode: '755'
loop:
- preview
- name: preview
dest: '{{ xdg_dir.bin_home }}/preview.sh'
- name: bukumenu
dest: '{{ xdg_dir.libexec_dir }}/wayland/bukumenu'
- name: calcmenu
dest: '{{ xdg_dir.libexec_dir }}/wayland/calcmenu'
- name: clipboard
dest: '{{ xdg_dir.libexec_dir }}/wayland/clipboard'
- name: dismiss_notify
dest: '{{ xdg_dir.libexec_dir }}/wayland/dismiss_notify'
- name: launch_wallpaper
dest: '{{ xdg_dir.libexec_dir }}/wayland/launch_wallpaper'
- name: mangamenu
dest: '{{ xdg_dir.libexec_dir }}/wayland/mangamenu'
- name: musicmenu
dest: '{{ xdg_dir.libexec_dir }}/wayland/musicmenu'
- name: notifymenu
dest: '{{ xdg_dir.libexec_dir }}/wayland/notifymenu'
- name: screenshot
dest: '{{ xdg_dir.libexec_dir }}/wayland/screenshot'
- name: searchmenu
dest: '{{ xdg_dir.libexec_dir }}/wayland/searchmenu'
- name: sway_window
dest: '{{ xdg_dir.libexec_dir }}/wayland/sway_window'
- name: Install external scripts with curl
import_tasks: curl.yml
@ -54,6 +59,6 @@
- name: Symlink jq executable to {{ jq_binary }}
file:
src: '{{ jq_binary }}'
dest: ~/.local/bin/jq
dest: '{{ xdg_dir.bin_home }}/jq'
state: link
force: true

View File

@ -157,7 +157,7 @@ if [[ $mimetype == application/x-7z-compressed ]]; then
fi
if [[ $mimetype == @(application/vnd.efi.iso|application/x-*-rom|application/x-compressed-iso|application/x*-iso?(9660)-?(app)image) ]]; then
isoinfo -l -i "$FILE" || bsdtar -tf "$FILE"
isoinfo -f -i "$FILE" || bsdtar -tf "$FILE"
exit
fi
@ -166,7 +166,12 @@ if [[ $mimetype == application/x-cpio* ]]; then
exit
fi
if [[ $mimetype == @(application/?(x-)gzip|application/vnd.ms-cab-compressed|application/x-archive|application/?(x-)bzip*|application/x-lzma|application/x-lzip|application/x-lha|application/x-lzh-compressed|application/x-lhz|application/x-lzop|application/x-lz4|application/x-lrzip) ]]; then
if [[ $mimetype == application/?(x-)gzip ]]; then
bsdtar -tf "$FILE" || gzip -l "$FILE"
exit
fi
if [[ $mimetype == @(application/vnd.ms-cab-compressed|application/x-archive|application/?(x-)bzip*|application/x-lzma|application/x-lzip|application/x-lha|application/x-lzh-compressed|application/x-lhz|application/x-lzop|application/x-lz4|application/x-lrzip) ]]; then
bsdtar -tf "$FILE"; exit
fi