File tree Expand file tree Collapse file tree 3 files changed +56
-3
lines changed Expand file tree Collapse file tree 3 files changed +56
-3
lines changed Original file line number Diff line number Diff line change 1
1
# Scripts
2
2
3
3
These are misc scripts I've made over the years to help with different things.
4
-
5
- It's migrated from [ lindhe/dotfiles] ( https://github.com/lindhe/dotfiles ) and I couldn't be bothered getting the history too.
6
- So the old stuff is in the history over there.
Original file line number Diff line number Diff line change
1
+ # Terminal
2
+
3
+ Terminal helper programs.
4
+
5
+ * ` copy.sh ` : Copy the contents of a file to the clipboard.
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+ # Copy the contents of a file to the clipboard.
3
+
4
+ set -euo pipefail
5
+
6
+ stderr () {
7
+ echo " ${@ } " 1>&2
8
+ }
9
+
10
+ fail () {
11
+ stderr " ${1} "
12
+ stderr " "
13
+ stderr " Exiting …"
14
+ exit " ${2:- 1} "
15
+ }
16
+
17
+ if [[ $# -ne 1 ]]; then
18
+ stderr " "
19
+ stderr " USAGE:"
20
+ stderr " ${0} <file>"
21
+ stderr " "
22
+ exit 0
23
+ fi
24
+
25
+ if [[ " $( uname -r) " =~ .* microsoft.* ]]; then
26
+ declare -r IS_WSL=true
27
+ else
28
+ declare -r IS_WSL=false
29
+ fi
30
+
31
+ if [[ " ${IS_WSL} " == " false" ]]; then
32
+ missing_dependencies=false
33
+ declare -r dependencies=(
34
+ xclip
35
+ )
36
+ for dep in " ${dependencies[@]} " ; do
37
+ if ! command -v " ${dep} " & > /dev/null; then
38
+ stderr " ❌ ERROR: Missing dependency ${dep} "
39
+ missing_dependencies=true
40
+ fi
41
+ done
42
+ if ${missing_dependencies} ; then
43
+ fail ' Please install the missing dependencies!'
44
+ fi
45
+ fi
46
+
47
+ if [[ " ${IS_WSL} " == " true" ]]; then
48
+ /mnt/c/Windows/System32/clip.exe < " ${1} "
49
+ else
50
+ xclip -selection clipboard < " ${1} "
51
+ fi
You can’t perform that action at this time.
0 commit comments