-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIpAddress.py
58 lines (40 loc) · 1.59 KB
/
IpAddress.py
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
import sublime
import sublime_plugin
from .ipaddress.IpAddress import IpAddress
def insert(view, edit, ip):
if ip is None:
sublime.error_message("Unable to retrieve IP address")
return
for region in view.sel():
if not region.empty():
view.replace(edit, region, ip)
else:
view.insert(edit, region.begin(), ip)
def set_clipboard(ip):
if ip is None:
sublime.error_message("Unable to retrieve IP address")
return
sublime.set_clipboard(ip)
sublime.status_message("IP address {0} was copied to clipboard".format(ip))
class InsertIpAddressCommand(sublime_plugin.TextCommand):
def run(self, edit):
insert(self.view, edit, IpAddress.instance().get('ipv4'))
class InsertIpv6AddressCommand(sublime_plugin.TextCommand):
def run(self, edit):
insert(self.view, edit, IpAddress.instance().get('ipv6'))
class SetClipboardIpAddressCommand(sublime_plugin.WindowCommand):
def run(self):
set_clipboard(IpAddress.instance().get('ipv4'))
class SetClipboardIpv6AddressCommand(sublime_plugin.WindowCommand):
def run(self):
set_clipboard(IpAddress.instance().get('ipv6'))
class RefreshIpAddressCommand(sublime_plugin.WindowCommand):
def run(self):
ipv4 = IpAddress.instance().get('ipv4', True)
ipv6 = IpAddress.instance().get('ipv6', True)
if ipv4 is None and ipv6 is None:
sublime.error_message("Unable to retrieve IP address")
else:
sublime.status_message(
"IP address was refreshed: {0}".format(ipv4)
)