···11-# my-bash-scripts
22-33-These are the basic bash scripts I've made for myself. They're made for macOS, so there's no guarantee they'll work on other OSes.
44-55-# Install
66-77-1. Download the scripts and put them in whatever folder you want. In my case, they are in `~/dev/my-bash-scripts/bin`.
88-2. Now you need to make the scripts executable. You can do that by running `chmod +x <YOUR_FOLDER>/*`.
99-3. Lastly, add the folder to your PATH, so you can call the scripts by their filename in your terminal from anywhere. Edit the file named `.bash_profile` (or create it if it does not exist). Add the following line to it: `export PATH=<YOUR_FOLDER>:$PATH`.
1010-1111-# Scripts
1212-1313-## welp
1414-Super simple script that lists the files in the same folder as the script is in. In other words, it lists the scripts here.
1515-1616-## chill
1717-Stops execution for a specified amount of time. Useful for scheduling stuff. `chill` shows the syntax:
1818-```
1919-Syntax: chill #h
2020-Syntax: chill #m
2121-Syntax: chill #h #m
2222-```
2323-2424-## d-c
2525-Basic wrapper around the `docker-compose` command (which you should have if you got Docker installed). The command works the same as `docker-compose`, except:
2626-- When running `d-c run`, it automatically adds the `--rm` argument
2727-- When running `d-c up`, it automatically runs `docker-compose down` afterwards.
2828-2929-## render
3030-This will render [After Effects](https://www.adobe.com/products/aftereffects.html) projects, assuming you have After Effects installed in `/Applications/Adobe After Effects CC 2019` (Specifically, the `aerender` file needs to be in there). Running `render` shows the syntax:
3131-```
3232-Usage:
3333- render <file> [file...]
3434-3535-Options:
3636- file After Effects .aep file for After Effects' aerender to render.
3737-```
3838-It was made to be able to support multiple path arguments, as well as taking folders as path arguments to render every .aep file inside those folders, but I don't think that works. Might fix that someday if I need it.
3939-4040-## reset-permissions
4141-Resets permissions of a directory. You should probably know what you're doing before running this.
4242-4343-Running `reset-permissions` shows the syntax:
4444-```
4545-reset-permissions
4646-usage: reset-permissions <username> <directory>
4747-```
4848-4949-This is the command it will run:
5050-```
5151-sudo chmod -RN <DIRECTORY> && \
5252-sudo chown -R <USERNAME> <DIRECTORY> && \
5353-sudo chmod -R 755 <DIRECTORY>
5454-```
5555-5656-## sleepy
5757-Hibernates your computer. I usually run this after `render` or `chill`.
5858-5959-## to
6060-Requires [ImageMagick](https://imagemagick.org) for images and [FFmpeg](https://ffmpeg.org) for audio and video. I recommend installing them using [Brew](https://brew.sh) by running `brew install ffmpeg imagemagick`.
6161-6262-Converts audio and video. Running `to` shows this help message:
6363-```
6464-Usage:
6565- to <format> [options] <file1> [file2...]
6666-6767-Options:
6868- format Format to convert to.
6969- --formats List all supported formats.
7070- -v, --verbose If you love logs.
7171- -h, --help Show this help message.
7272-7373- Video/audio formats support FFmpeg options (see $ ffmpeg -h).
7474- Image formats support ImageMagick options (see $ man magick).
7575- Long arguments must have quotes (like "-b:a 128k").
7676-```
7777-7878-## to-gif
7979-Requires [ffmpeg](https://ffmpeg.org) (which I recommend installing using [Brew](https://brew.sh)).
11+# to
8028181-Converts videos into gifs. If you do this frequently I would probably use some app instead.
8282-8383-Running `to-gif` shows the syntax:
8484-```
8585-Syntax: to-gif <file> [fps] [scale] [duration] [start_at]
8686- file: File to convert to gif. Required.
8787- fps: Defaults to 15.
8888- scale: GIF resolution. Defaults to 1.
8989- duration: How long the gif will be, in seconds. Defaults to 999999.
9090- start_at: Where the video starts, in seconds. Defaults to 0
9191-```
33+Pretty simple bash script that converts audio, video and image files using FFmpeg and ImageMagick.
···11-#!/bin/sh
22-33-FILE=$1
44-FPS=$2
55-SCALE=$3
66-DURATION=$4
77-START_AT=$5
88-99-if [[ $FILE ]]
1010-then
1111-1212- if ! [[ $FPS ]]; then FPS=15; fi
1313- if ! [[ $SCALE ]]; then SCALE=1; fi
1414- if ! [[ $DURATION ]]; then DURATION=999999; fi
1515- if ! [[ $START_AT ]]; then START_AT=0; fi
1616-1717- PALETTE=palette-rp7w8zsw2dx83dsxrgqmt6f5.png
1818-1919- echo "Generate a palette:"
2020- ffmpeg -y -ss $START_AT -t $DURATION -i $FILE -vf fps=$FPS,scale=w=${SCALE}*iw:h=${SCALE}*ih:-1:flags=lanczos,palettegen ${PALETTE}
2121-2222- echo "Output the GIF using the palette:"
2323- ffmpeg -ss $START_AT -t $DURATION -i $FILE -i ${PALETTE} -filter_complex "fps=${FPS},scale=w=${SCALE}*iw:h=${SCALE}*ih:flags=lanczos[x];[x][1:v]paletteuse" ${FILE%.*}.gif
2424-2525- rm -f ${PALETTE}
2626-2727-else
2828- SCRIPT_FILENAME=${0##*/}
2929- echo "Syntax: $SCRIPT_FILENAME <file> [fps] [scale] [duration] [start_at]"
3030- echo " file: File to convert to gif. Required."
3131- echo " fps: Defaults to 15."
3232- echo " scale: GIF resolution. Defaults to 1."
3333- echo " duration: How long the gif will be, in seconds. Defaults to 999999."
3434- echo " start_at: Where the video starts, in seconds. Defaults to 0"
3535-fi
-7
bin/welp
···11-#! /bin/bash
22-33-# get the dir that the file is in
44-DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
55-66-echo These scripts are installed in $DIR:
77-ls -1 $DIR