Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuhrmann committed Mar 29, 2018
0 parents commit 5a68e10
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = crlf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{md,rst,txt}]
indent_size = 2
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
.idea
.vscode
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<p align="center">
<img src="src/myip.ico" width="100" height="100" />
</p>

# Keypirinha Plugin: MyIP

This is MyIP, a plugin for the
[Keypirinha](http://keypirinha.com) launcher.

Get your public and local IP directly from Keypirinha.

![Demo](usage.png)

## Download
https://github.com/Fuhrmann/keypirinha-myip/releases/latest

## Install

#### Managed
[@ueffel](https://github.com/ueffel) wrote [PackageControl](https://github.com/ueffel/Keypirinha-PackageControl), a package manager that eases the install of third-party packages.
It must be installed manually.

#### Manual
Once the `MyIP.keypirinha-package` file is installed,
move it to the `InstalledPackage` folder located at:

* `Keypirinha\portable\Profile\InstalledPackages` in **Portable mode**
* **Or** `%APPDATA%\Keypirinha\InstalledPackages` in **Installed mode** (the
final path would look like
`C:\Users\%USERNAME%\AppData\Roaming\Keypirinha\InstalledPackages`)


## Usage

Open Keypirinha and type 'ip' or 'IP'. Your local and public IP will appear on Keypirinha's catalog. Press `ENTER` to copy.

## Change Log
### v1.0
* Released


## License
This package is distributed under the terms of the MIT license.


## Credits
The icon used in this plugin was provided by [icons8](https://icons8.com)
57 changes: 57 additions & 0 deletions make.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@echo off
setlocal

set PACKAGE_NAME=MyIP
set INSTALL_DIR=%APPDATA%\Keypirinha\InstalledPackages

if "%1"=="" goto help
if "%1"=="-h" goto help
if "%1"=="--help" goto help
if "%1"=="help" (
:help
echo Usage:
echo make help
echo make clean
echo make build
echo make install
echo make py [python_args]
goto end
)

if "%BUILD_DIR%"=="" set BUILD_DIR=%~dp0build
if "%KEYPIRINHA_SDK%"=="" (
echo ERROR: Keypirinha SDK environment not setup.
echo Run SDK's "kpenv" script and try again.
exit /b 1
)

if "%1"=="clean" (
if exist "%BUILD_DIR%" rmdir /s /q "%BUILD_DIR%"
goto end
)

if "%1"=="build" (
if not exist "%BUILD_DIR%" mkdir "%BUILD_DIR%"
pushd "%~dp0"
call "%KEYPIRINHA_SDK%\cmd\kparch" ^
"%BUILD_DIR%\%PACKAGE_NAME%.keypirinha-package" ^
-r LICENSE* README* src
popd
goto end
)

if "%1"=="install" (
echo TODO: ensure the INSTALL_DIR variable declared at the top of this
echo script complies to your configuration and remove this message
exit /1

copy /Y "%BUILD_DIR%\*.keypirinha-package" "%INSTALL_DIR%\"
goto end
)

if "%1"=="py" (
call "%KEYPIRINHA_SDK%\cmd\kpy" %2 %3 %4 %5 %6 %7 %8 %9
goto end
)

:end
Binary file added src/myip.ico
Binary file not shown.
70 changes: 70 additions & 0 deletions src/myip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Keypirinha launcher (keypirinha.com)

import socket

import keypirinha as kp
import keypirinha_net as kpnet
import keypirinha_util as kpu


class MyIP(kp.Plugin):
"""
Get your public and local IP directly from Keypirinha.
"""

ITEM_CAT = kp.ItemCategory.USER_BASE + 1
KEYWORD = 'ip'

def __init__(self):
super().__init__()
self._urlopener = kpnet.build_urllib_opener()

def on_suggest(self, user_input, items_chain):
if user_input.lower() == self.KEYWORD:
public_ip = self._get_public_ip()
local_ip = self._get_local_ip()

self.set_catalog(
[
self.create_item(
category=kp.ItemCategory.KEYWORD,
label='Your public IP',
short_desc=public_ip,
target='public_ip',
args_hint=kp.ItemArgsHint.FORBIDDEN,
hit_hint=kp.ItemHitHint.NOARGS
),
self.create_item(
category=kp.ItemCategory.KEYWORD,
label='Your local IP',
short_desc=local_ip,
target='local_ip',
args_hint=kp.ItemArgsHint.FORBIDDEN,
hit_hint=kp.ItemHitHint.NOARGS
)
]
)

def on_execute(self, item, action):
kpu.set_clipboard(item.short_desc())

def on_events(self, flags):
if flags & kp.Events.NETOPTIONS:
self._urlopener = kpnet.build_urllib_opener()

def _get_public_ip(self):
try:
with self._urlopener.open('http://icanhazip.com') as res:
return res.read().decode('utf-8')
except Exception as ex:
self.err(ex)
return 'Could not establish your public ip'

def _get_local_ip(self):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
return s.getsockname()[0]
except Exception as ex:
self.err(ex)
return 'Could not establish your local ip'
Binary file added usage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5a68e10

Please sign in to comment.