Skip to content

Instantly share code, notes, and snippets.

@trailjeep
Last active September 28, 2021 01:10
Show Gist options
  • Save trailjeep/9d94dac22c7524cc30347eac9f6a16c6 to your computer and use it in GitHub Desktop.
Save trailjeep/9d94dac22c7524cc30347eac9f6a16c6 to your computer and use it in GitHub Desktop.
description
[[snippets]]
description = "Convert seconds since the epoch (1970-01-01 UTC) to a date"
command = "date -d @1440359821"
tag = ["epoch"]
output = "Sun Aug 23 15:57:01 EDT 2015"
[[snippets]]
description = "Date / timestamp as seconds since epoch"
command = "date +%s"
tag = ["timestamp", "epoch"]
output = "1551295966"
[[snippets]]
description = "Recursively grep for string <pattern> in folder and print matching files"
command = "grep -Rl pattern folder"
tag = ["recurse"]
output = ""
[[snippets]]
description = "Find lines NOT containing pattern"
command = "grep -v pattern file"
tag = ["not"]
output = ""
[[snippets]]
description = "Date / timestamp human readable"
command = "date +\"%Y%m%d_%H%M%S\""
tag = ["timestamp"]
output = "20190228_120344"
[[snippets]]
description = "Encrypt string with OpenSSL"
command = "echo string | openssl aes-256-cbc -pbkdf2 -e | openssl base64 -e"
tag = ["encryption", "openssl", "aes-256"]
output = "U2FsdGVkX193oGHZmNNRtU/3oczNZNJpUUGad3vhKtg="
[[snippets]]
description = "Decrypt string with OpenSSL"
command = "echo \"U2FsdGVkX193oGHZmNNRtU/3oczNZNJpUUGad3vhKtg=\" | openssl base64 -d | openssl aes-256-cbc -pbkdf2 -d"
tag = ["encryption", "openssl", "aes-256"]
output = "string"
[[snippets]]
description = "Encrypt file with OpenSSL"
command = "openssl aes-256-cbc -pbkdf2 -e -in DECFILE -out ENCFILE"
tag = ["encryption", "openssl", "aes-256"]
output = ""
[[snippets]]
description = "Decrypt file with OpenSSL"
command = "openssl aes-256-cbc -pbkdf2 -d -in ENCFILE -out DECFILE"
tag = ["encryption", "openssl", "aes-256"]
output = ""
[[snippets]]
description = "Encrypt directory with OpenSSL"
command = "tar cz DIR | openssl aes-256-cbc -pbkdf2 -e -out ENCFILE"
tag = ["encryption", "openssl", "aes-256"]
output = ""
[[snippets]]
description = "Decrypt directory with OpenSSL"
command = "openssl aes-256-cbc -pbkdf2 -d -in ENCFILE | tar xz"
tag = ["encryption", "openssl", "aes-256"]
output = ""
[[snippets]]
description = "Write ISO image to USB drive"
command = "dd if=FILE.iso of=/dev/sdX bs=4M status=progress && sync"
tag = ["iso", "usb", "livecd"]
output = ""
[[snippets]]
description = "dconf write string"
command = "dconf write /com/deepin/wrap/gnome/desktop/wm/preferences/focus-mode \"string 'sloppy'\""
tag = ["dconf", "string"]
output = ""
[[snippets]]
description = "dconf write boolean or integer"
command = "dconf write /com/deepin/wrap/gnome/desktop/wm/preferences/auto-raise false"
tag = ["dconf", "boolean", "integer"]
output = ""
[[snippets]]
description = "Screenshot website"
command = "/bin/google-chrome-unstable --headless --hide-scrollbars --screenshot=\"$HOME/Downloads/FILE\" \"URL\" # --window-size=1024,2550"
tag = ["chrome", "screenshot", "website"]
output = ""
[[snippets]]
description = "Display A/V File Tags"
command = "ffprobe FILE"
tag = ["ffmpeg", "ffprobe", "tags", "audio", "video"]
output = ""
[[snippets]]
description = "Create & checkout new branch"
command = "git checkout -b <BRANCH>"
tag = ["git", "branch"]
output = ""
[[snippets]]
description = "Delete local branch"
command = "git branch -d <LOCAL_BRANCH>"
tag = ["git", "branch"]
output = ""
[[snippets]]
description = "Delete remote branch"
command = "git push origin --delete <REMOTE_BRANCH>"
tag = ["git", "branch"]
output = ""
[[snippets]]
description = "Copy files from another branch into current"
command = "git checkout <BRANCH> <PATHS>..."
tag = ["git", "branch", "copy", "files"]
output = ""
[[snippets]]
description = "Optimize png images and strip all metadata"
command = "optipng -strip all image.png"
tag = ["images", "png", "optimize"]
output = ""
[[snippets]]
description = "Resize images while preserving aspect ratio (200x100! will force size)"
command = "convert example.png -resize 200x100 example.png"
tag = ["imagemagick", "images", "resize"]
output = ""
[[snippets]]
description = "parse XML file (stdin = -) for tag value (beware XMLNS)"
command = "echo \"<dewpoint_f>26.1</dewpoint_f>\" | xmllint --xpath \"string(//dewpoint_f)\" -"
tag = ["xml", "parse"]
output = "26.1"
[[snippets]]
description = "ImageMagick convert BG to transparent (PNG or GIF support transparency)"
command = "convert IMAGE.{gif|png} -transparent white IMAGE.{gif|png}"
tag = ["imagemagick", "transparent", "background"]
output = ""
[[snippets]]
description = "Add user to multiple groups"
command = "sudo usermod -aG GROUP1,GROUP2 USER"
tag = ["users", "groups"]
output = ""
[[snippets]]
description = "Remove package depended upon by another package"
command = "pacman -Rdd wpa_supplicant"
tag = ["pacman", "remove", "dependencies"]
output = ""
[[snippets]]
description = "Restart Plasma"
command = "plasmashell --replace &"
tag = ["plasma", "restart"]
output = ""
[[snippets]]
description = "Show tree view of mounted filesystems"
command = "findmnt"
tag = ["mount", "filesystems"]
output = ""
[[snippets]]
description = "Play podcast @ 1.5x speed without affecting pitch optimized for speech"
command = "play science-friday121418a.mp3 tempo -s 1.5"
tag = ["audio", "podcasts", "sox"]
output = ""
[[snippets]]
description = "Convert podcast to 1.5x speed without affecting pitch optimized for speech & show progress"
command = "sox -S science-friday121418a.mp3 test.mp3 tempo -s 1.5"
tag = ["audio", "podcast", "sox", "convert"]
output = ""
[[snippets]]
description = "Play podcast @ 1.5x speed without affecting pitch"
command = "mplayer -af scaletempo -speed 1.5 HSW9914000083.mp3"
tag = ["audio", "podcasts", "mplayer"]
output = ""
[[snippets]]
description = "Sanitize filenames: Rename files to UTF8, special chars to _, & lowercase"
command = "detox -s utf_8 -s lower *"
tag = ["sanitize", "rename", "detox", "filenames", "files"]
output = ""
[[snippets]]
description = "List apps not in a registered repo or PPA"
command = "apt-show-versions | grep 'No available version'"
tag = ["apt", "packages", "repos"]
output = ""
[[snippets]]
description = "List packages from a particular repo or PPA"
command = "awk '$1 == \"Package:\" { if (a[$2]++ == 0) print $2; }' /var/lib/apt/lists/*PARTOFREPONAME*Packages"
tag = ["apt", "packages", "repos"]
output = ""
[[snippets]]
description = "Grep exclude by regex"
command = "grep -Ev \"^(PAT1|PAT2|PAT3)\""
tag = ["grep", "exclude", "not", "regex", "pattern"]
output = ""
[[snippets]]
description = "Concatenate video files (same type) w/ffmpeg"
command = "ffmpeg -i \"concat:VTS_02_1.VOB|VTS_02_2.VOB|VTS_02_3.VOB\" -c copy COMBINED.vob"
tag = ["ffmpeg", "cat", "combine", "video"]
output = ""
[[snippets]]
description = "Concatenate MKV video files"
command = "mkvmerge -o COMBINED.mkv 1-1.mkv +1-2.mkv +1-3.mkv +..."
tag = ["video", "concatenate", "mkv", "mkvmerge"]
output = ""
[[snippets]]
description = "Backup DVD main feature to hd"
command = "dvdbackup -i /dev/sr0 -o ~/Videos/ -F -p"
tag = ["dvd", "backup", "dvdbackup", "video"]
output = ""
[[snippets]]
description = "Format whole HD as BTRFS"
command = "sudo mkfs.btrfs /dev/sdX"
tag = ["format", "btrfs", "filesystem", "hd"]
output = ""
[[snippets]]
description = "List Network connections (TCP/UDP/State/User/Program)"
command = "netstat -netulp"
tag = ["networking", "netstat", "connections", "tcp", "udp"]
output = ""
[[snippets]]
description = "Generate video thumbnails for Samsung and minidlna"
command = "for f in *.mp4; do ffmpegthumbnailer -a -m -s 512 -i \"$f\" -o \"$f\".cover.jpg; done"
tag = ["video", "thumbnail", "dlna", "minidlna", "samsung"]
output = ""
[[snippets]]
description = "Burn subtitles into movie"
command = "ffmpeg -i video.mp4 -vf subtitles=video.srt out.mp4"
tag = ["video", "ffmpeg", "subtitles"]
output = ""
[[snippets]]
description = "Add subtitle as optional track to movie"
command = "ffmpeg -i infile.mp4 -i infile.srt -c copy -c:s mov_text outfile.mp4"
tag = ["ffmpeg", "videos", "subtitles"]
output = ""
[[snippets]]
description = "Send a test desktop notification."
command = "notify-send 'Test' 'This is a test notification.' --icon=dia  SIGINT ation"
tag = ["notification", "test"]
output = ""
[[snippets]]
description = "BASH check dependencies (https://stackoverflow.com/a/50927961)"
command = "[[ \"$(command -v COMMAND)\" ]] || { echo \"Missing dependency: COMMAND\" 1>&2 ; exit 1; }"
tag = ["bash", "script", "dependency", "dependencies", "command"]
output = ""
[[snippets]]
description = "BASH get file path"
command = "echo \"${file%/*}\""
tag = ["bash", "script", "path"]
output = ""
[[snippets]]
description = "BASH get file basename"
command = "echo \"${file##*/}\""
tag = ["bash", "script", "basename"]
output = ""
[[snippets]]
description = "BASH get filename without extension"
command = "echo \"${file%.*}\""
tag = ["bash", "script", "basename", "extension"]
output = ""
[[snippets]]
description = "Batch rename file extensions (html->txt)"
command = "for f in *.html; do mv \"$f\" \"${f%.html}.txt\"; done"
tag = ["batch", "rename", "extension", "file"]
output = ""
[[snippets]]
description = "PHP get next/previous month (https://stackoverflow.com/a/3931005)"
command = "echo date(\"Y-m\", mktime(0, 0, 0, $month-1, 1, $year));"
tag = ["php", "calendar", "month"]
output = ""
[[snippets]]
description = "BASH if array contains (https://stackoverflow.com/a/15394738)"
command = "[[ \" ${array[@]} \" =~ \" ${value} \" ]] && echo \"true\" || echo \"false\""
tag = ["bash", "variables", "arrays", "contains"]
output = ""
[[snippets]]
description = "BASH test if dir is empty (https://superuser.com/q/352289)"
command = "[ \"$(find \"$DIR\" -maxdepth 0 -empty)\" ] && echo \"empty\" || echo \"not empty\""
tag = ["bash", "directory", "empty", "test"]
output = ""
[[snippets]]
description = "BASH script pass command options as array\n\t[Using shell variables for command options](https://unix.stackexchange.com/a/459369)"
command = "opts=( -r -n -v --exclude='.*' ) # TO USE # \"${opts[@]}\""
tag = ["bash", "script", "command", "options", "variables", "arrays"]
output = ""
[[snippets]]
description = "BASH test for root (maybe chown root & chmod 0764 also)"
command = "[[ $EUID -ne 0 ]] && echo \"not root\" || echo \"root\""
tag = ["bash", "test", "root"]
output = ""
[[snippets]]
description = "BASH get script source\n\t[choosing between $0 and BASH_SOURCE](https://stackoverflow.com/a/63072463)"
command = "\"${BASH_SOURCE[0]:-$0}\""
tag = ["bash", "script", "source", "path"]
output = ""
[[snippets]]
description = "Midnight Commander select all"
command = "Alt+Shift+= \"*\""
tag = ["mc", "shortcuts", "select"]
output = ""
[[snippets]]
description = "Yakuake switch tabs"
command = "Shift+<- | Shift+-> | Alt+1...Alt+9"
tag = ["yakuake", "tabs", "switch"]
output = ""
[[snippets]]
description = "Sanitize filenames: Remove Illegal Characters"
command = "find -depth -execdir rename \"s/[\\\\:*?\\\"<>|\\n]//g\" \"{}\" \\;"
tag = ["sanitize", "rename", "filenames"]
output = ""
[[snippets]]
description = "Sanitize filenames: Remove Trailing Dots"
command = "find -depth -execdir rename \"s/[\\.]+$//\" \"{}\" \\;"
tag = ["sanitize", "rename", "filenames"]
output = ""
[[snippets]]
description = "Sanitize filenames: Trim Leading Whitespace"
command = "find -depth -execdir rename \"s/^(\\.\\/)\\s+/$1/\" \"{}\" \\;"
tag = ["sanitize", "rename", "filenames"]
output = ""
[[snippets]]
description = "Sanitize filenames: Trim Trailing Whitespace"
command = "find -depth -execdir rename \"s/\\s+$//\" \"{}\" \\;"
tag = ["sanitize", "rename", "filenames"]
output = ""
[[snippets]]
description = "Sanitize filenames: Replace Remaining Whitespace With Underscores"
command = "find -depth -execdir rename \"s/\\s+/_/g\" \"{}\" \\;"
tag = ["sanitize", "rename", "filenames"]
output = ""
[[snippets]]
description = "Continue interrupted downloads and get filename from server"
command = "alias wget='wget --continue --content-disposition'"
tag = ["wget", "continue", "filenames"]
output = ""
[[snippets]]
description = "Logout other users (must be root)"
command = "pkill -KILL -u {username}"
tag = ["logout", "kill", "root", "users"]
output = ""
[[snippets]]
description = "Undo stow symlinked dotfiles (copy file over symlink including directories)\n\t[List symbolic links and location, pointing to a particular directory](htt ps://stackoverflow.com/a/4631339)\n\t[How to convert symlink to regular file?](https://stackoverflow.com/a/30295776)"
command = "find . -type l -exec ls -l {} \\; | grep -- 'dotfiles/' | awk '{ print $9 }' > files.txt && while read file; do temp=\"$(readlink -f \"$file\")\"; rm -rf \"$file\"; cp -rf \"$temp\" \"$file\"; echo \"$file unlinked from $temp\"; done < files.txt"
tag = ["stow", "symlinks", "copy", "unlink", "dotfiles"]
output = ""
[[snippets]]
description = "backup (move/rename) existing rsync destination files (without --backup-dir --suffix='~' with --suffix='')\n\t[How to backup files before overwriting them with rsync](https://stackoverflow.com/a/53742271)"
command = "rsync --backup --backup-dir=\".DIST_CONF\" --suffix=\".BAK\""
tag = ["rsync", "backups", "files"]
output = ""
[[snippets]]
description = "See disk usage of system journal"
command = "journalctl --disk-usage"
tag = ["systemd", "journal"]
output = ""
[[snippets]]
description = "Clear system journal to target size"
command = "sudo journalctl --vacuum-size=200M"
tag = ["systemd", "journal", "vacuum", "clear"]
output = ""
[[snippets]]
description = "Find largest files in home dir"
command = "du -ahx ~ | sort -rh | head -15"
tag = ["disk", "space", "usage"]
output = ""
[[snippets]]
description = "update pkglist w/explicitly installed distro repo pkgs"
command = "pacman -Qqetn > pacman.dist"
tag = ["pacman", "pkglist", "distro"]
output = ""
[[snippets]]
description = "update pkglist w/explicitly installed foreign (aur) pkgs"
command = "pacman -Qqem > pacman.foreign"
tag = ["pacman", "pkglist", "foreign", "aur"]
output = ""
[[snippets]]
description = "Iterate lines of a newline seperated file"
command = "IFS=$'\\n'; while read line; do echo \"$line\"; done < FILE; unset IFS"
tag = ["bash", "while", "read"]
output = ""
[[snippets]]
description = "Set timeout to prevent hangs"
command = "/usr/bin/timeout 5m gcalcli agenda"
tag = ["cron"]
output = ""
[[snippets]]
description = "Generate random alphanumeric string"
command = "tr -dc '[:alnum:]' </dev/urandom | fold -w ${1:-5} | head -n1"
tag = ["urandom", "tr", "fold", "head", "random"]
output = ""
[[snippets]]
description = "Find create date of file/folder"
command = "stat / | tail -1"
tag = ["stat", "ctime", "create", "date"]
output = ""
[[snippets]]
description = "Find install date of Arch-like distros"
command = "head -n1 /var/log/pacman.log | awk '{print \"Install date: \"$1}' | tr -d '['"
tag = ["arch", "pacman", "date", "install"]
output = ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment