-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create script for copying file contents
- Loading branch information
Showing
3 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
# Scripts | ||
|
||
These are misc scripts I've made over the years to help with different things. | ||
|
||
It's migrated from [lindhe/dotfiles](https://github.com/lindhe/dotfiles) and I couldn't be bothered getting the history too. | ||
So the old stuff is in the history over there. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Terminal | ||
|
||
Terminal helper programs. | ||
|
||
* `copy.sh`: Copy the contents of a file to the clipboard. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env bash | ||
# Copy the contents of a file to the clipboard. | ||
|
||
set -euo pipefail | ||
|
||
stderr() { | ||
echo "${@}" 1>&2 | ||
} | ||
|
||
fail() { | ||
stderr "${1}" | ||
stderr "" | ||
stderr "Exiting …" | ||
exit "${2:-1}" | ||
} | ||
|
||
if [[ $# -ne 1 ]]; then | ||
stderr "" | ||
stderr "USAGE:" | ||
stderr " ${0} <file>" | ||
stderr "" | ||
exit 0 | ||
fi | ||
|
||
if [[ "$(uname -r)" =~ .*microsoft.* ]]; then | ||
declare -r IS_WSL=true | ||
else | ||
declare -r IS_WSL=false | ||
fi | ||
|
||
if [[ "${IS_WSL}" == "false" ]]; then | ||
missing_dependencies=false | ||
declare -r dependencies=( | ||
xclip | ||
) | ||
for dep in "${dependencies[@]}"; do | ||
if ! command -v "${dep}" &> /dev/null; then | ||
stderr "❌ ERROR: Missing dependency ${dep}" | ||
missing_dependencies=true | ||
fi | ||
done | ||
if ${missing_dependencies}; then | ||
fail 'Please install the missing dependencies!' | ||
fi | ||
fi | ||
|
||
if [[ "${IS_WSL}" == "true" ]]; then | ||
/mnt/c/Windows/System32/clip.exe < "${1}" | ||
else | ||
xclip -selection clipboard < "${1}" | ||
fi |