Skip to content

Commit

Permalink
Merge pull request #2 from ilyakam/release/1.0.0
Browse files Browse the repository at this point in the history
chore(*): release version 1.0.0
  • Loading branch information
ilyakam authored Apr 22, 2018
2 parents 4bdd098 + 4d3e726 commit f83c0e0
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Unifying editor configurations for all developers:
# For details see http://editorconfig.org/

root = true

[*]
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
*.pyc
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [1.0.0] - 2018-04-21
### Added:
- Ability to remove duplicate lines from the entire file
- Ability to remove all lines that match the selection
- Default keyboard shortcut: <kbd>shift</kbd><kbd>F5</kbd>
- Documentation: `README`, `CONTRIBUTING`, and `LICENSE`
38 changes: 38 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Contributing

Thank you for your interest in contributing to this project! Here's what you need to know to get started.

1. [Maintainers](#maintainers)
1. [Order of Operations](#order-of-operations)
1. [Getting Started](#getting-started)
1. [Commit Guidelines](#commit-guidelines)

## Maintainers

This project is currently being maintained by:

* Ilya Kaminsky ([@ilyakam](https://github.com/ilyakam/))

## Order of Operations

1. [Create a new issue](https://github.com/ilyakam/RemoveDuplicateLines/issues/new)
1. Fork the repo
1. Write code and thoroughly test it
1. [Submit a pull request](https://github.com/ilyakam/RemoveDuplicateLines/compare) against `develop`
1. Communicate in a timely manner while the PR is open

## Getting Started
1. Clone this repo (`~/code` is assumed)
```sh
cd ~/code
git clone [email protected]:ilyakam/RemoveDuplicateLines.git
```
1. Create an alias in your [Sublime Text's Packages folder](https://forum.sublimetext.com/t/9484) (macOS is assumed)
```sh
cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/
ln -s ~/code/RemoveDuplicateLines ./
```

## Commit Guidelines

Please follow the commit guidelines created by the AngularJS team. The latest version can be found [here](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#commits).
3 changes: 3 additions & 0 deletions Default (Linux).sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{"keys": ["shift+f5"], "command": "remove_duplicate_lines"}
]
3 changes: 3 additions & 0 deletions Default (OSX).sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{"keys": ["shift+f5"], "command": "remove_duplicate_lines"}
]
3 changes: 3 additions & 0 deletions Default (Windows).sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{"keys": ["shift+f5"], "command": "remove_duplicate_lines"}
]
11 changes: 11 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# License

The MIT License (MIT)

Copyright (c) 2018 Ilya Kaminsky

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.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# RemoveDuplicateLines - A Sublime Text Plugin

A plugin for [Sublime Text](http://www.sublimetext.com/) that allows you to remove duplicate lines from the file.

## Usage

<kbd>shift</kbd><kbd>F5</kbd> on all platforms. You might also need to hold <kbd>(fn)</kbd> depending on your OS/BIOS configuration.

There are two ways to use this plugin:

### Without a selection

This removes all duplicate lines, leaving each line to be unique to the entire file.

| Before | After |
| ------ | ----- |
| ![without_before](https://user-images.githubusercontent.com/183227/39089760-422a4866-4583-11e8-94e8-545983074fd4.png) | ![without_after](https://user-images.githubusercontent.com/183227/39089761-43da04f8-4583-11e8-9901-4a85e117d952.png) |

### With a selection

This removes all lines from the file that match the selection.

| Before | After |
| ------ | ----- |
| ![with_before](https://user-images.githubusercontent.com/183227/39089762-483acb22-4583-11e8-8ac5-aa6bcb3bb01e.png) | ![with_after](https://user-images.githubusercontent.com/183227/39089763-4a46dbcc-4583-11e8-9c65-c48674dcf77c.png)

## Changelog

See [CHANGELOG.md](./CHANGELOG.md)

## Contributing

See [CONTRIBUTING.md](./CONTRIBUTING.md)

## License

See [LICENSE.md](./LICENSE.md)
44 changes: 44 additions & 0 deletions remove_duplicate_lines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import sublime
import sublime_plugin

class RemoveDuplicateLinesCommand(sublime_plugin.TextCommand):
def run(self, edit):
"""
Removes duplicate lines so that each line contains a unique string
If a line is selected, it removes duplicate occurrences ONLY of the selection
"""

def delete_lines(needle, lines):
"""
Marks lines for deletion one by one and deletes them all at once
"""
needle_contents = self.view.substr(needle)
needle_size = needle.size()

for line in lines:
# Improve performance by comparing sizes before contents:
if (needle_size == line.size() and
needle_contents == self.view.substr(line)):

# Mark line for deletion by adding it to the selection:
self.view.sel().add(self.view.full_line(line))

# Avoid deleting the existing selection, if any
self.view.sel().subtract(needle)

# Delete all selections in reverse order to preserve the cursor position:
for deletion_selection in reversed(self.view.sel()):
self.view.replace(edit, deletion_selection, "")

self.view.sel().clear()

for region in self.view.sel():
# Select the entire file:
lines = self.view.lines(sublime.Region(0, self.view.size()))

if region.empty():
while len(lines) > 0:
delete_lines(lines.pop(0), lines)

else:
delete_lines(region, lines)

0 comments on commit f83c0e0

Please sign in to comment.