forked from ISUgenomics/common_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcb
executable file
·49 lines (40 loc) · 1.23 KB
/
cb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# cp2clip - copy to the clipboard the contents of a file
module load xclip
#PATH=/software//GIF/GIF/programs/xclip-0.12:$PATH
# Program name from it's filename
prog=${0##*/}
# Text color variables
bldblu='\e[1;34m' # blue
bldred='\e[1;31m' # red
bldwht='\e[1;37m' # white
txtbld=$(tput bold) # bold
txtund=$(tput sgr 0 1) # underline
txtrst='\e[0m' # text reset
info=${bldwht}*${txtrst}
pass=${bldblu}*${txtrst}
warn=${bldred}!${txtrst}
if [ "$#" -ne 1 ]; then
xclip -in -selection primary
echo -e "$pass ${txtund}"${filename##*/}"${txtrst} copied to clipboard"
else
filename=$@
# Display usage if full argument isn't given
if [[ -z $filename ]]; then
echo " $prog <filename> - copy a file to the clipboard"
exit
fi
# Check that file exists
if [[ ! -f $filename ]]; then
echo -e "$warn File ${txtund}$filename${txtrst} doesn't exist"
exit
fi
# Check user is not root (root doesn't have access to user xorg server)
if [[ $(whoami) == root ]]; then
echo -e "$warn Must be regular user to copy a file to the clipboard"
exit
fi
# Copy file to clipboard, give feedback
xclip -in -selection primary < "$filename"
echo -e "$pass ${txtund}"${filename##*/}"${txtrst} copied to clipboard"
fi