-
Notifications
You must be signed in to change notification settings - Fork 0
/
scpwd
executable file
·77 lines (64 loc) · 1.39 KB
/
scpwd
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash
# scpwd : secure copy pwd
#
# Quickly echo scp path including username@hostname and optional filename
#
# >>>
# /etc/ $ scpwd
# [email protected]:/etc
# /etc/ $ scpwd /opt/
# [email protected]:/opt
# /etc/ $ scpwd my.conf
# [email protected]:/etc/my.conf
# /etc/ $ scpwd /usr/local/etc/my.conf
# [email protected]:/usr/local/etc/my.conf
# /etc/ $ scpwd ../usr/local/etc/my.conf
# [email protected]:/usr/local/etc/my.conf
# <<<
#
# Florian Sager, [email protected], 2021-02-25, MIT license
# Optional config file to override user@hostname by
# >>>
# <<<
CONFIG_FILE="$HOME/.scpwd"
set -euo pipefail
function buildPwdFile {
local PWDFILE="$1"
local BUILTPATH
if [[ -z "$PWDFILE" ]]
then
BUILTPATH="`pwd`"
else
if [[ $PWDFILE == /* ]]
then
BUILTPATH="$PWDFILE"
else
BUILTPATH="`pwd`/$PWDFILE"
fi
fi
if [[ ! -e "$BUILTPATH" ]]
then
>&2 echo "Warning: path does not exist"
fi
echo `realpath -m "$BUILTPATH"` | sed 's/ /\\\\\\\ /g'
}
function buildHostName {
if [[ -z `hostname -d` ]]
then
hostname
else
hostname -f
fi
}
PATHIN=${1:-}
if [[ -s "$CONFIG_FILE" ]]
then
. "$CONFIG_FILE"
echo $LOGIN:$(buildPwdFile "$PATHIN")
elif [[ -z "${SSH_LOGIN_USER:-}" ]]
then
echo $USER@$(buildHostName):$(buildPwdFile "$PATHIN")
else
echo $SSH_LOGIN_USER@$(buildHostName):$(buildPwdFile "$PATHIN")
fi