-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfullpathto
executable file
·40 lines (33 loc) · 1.24 KB
/
fullpathto
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
#!/usr/bin/env python
# Print out the full path to a filename and copy it to the X clipboard.
# If multiple filenames are given, only the last one will be copied to
# the clipboard. Requires 'xclip' for clipboard copying but will still
# work without it.
# If your filesystem is filled with ugly symlinks, you can write
# a function called cleanup_path in the localsite.paths module.
# The function should take one string parameter with an absolute path
# and return a string. If this function can't be found, no cleanups will
# be performed. Example function:
# def cleanup_path(filename):
# if filename.startswith('/old/'):
# filename = filename[4:]
# return filename
# Usage: fullpathto [filenames]
# Author: David McClosky
# Homepage: http://zorglish.org
# Code: http://github.com/dmcc
import sys
import os
from pathlib import Path
try:
from localsite.paths import cleanup_path
except ImportError:
cleanup_path = lambda filename: filename
args = sys.argv[1:] or ['.']
for filename in args:
fullpath = Path(cleanup_path(Path(filename).absolute()))
print(fullpath)
if not fullpath.exists():
print('\twarning: above path does not exist')
command = "echo '%s' | xclip -in" % fullpath
os.system(command)