Skip to main content

A cli-based python tool designed to merge 2 files together interactively (using textual and python's difflib)

Project description

mergepy

[!important] TODO: Implement compatibility with git so it can be used as a mergetool

ℹ️ About

Mergepy is a cli-based python tool designed to merge 2 files together interactively by segmenting the 2 files into parts that are different and common. You easily select, then choose to keep or replace the conflicts by jumping between 2 panes and pressing enter (which will always replace a different part of the file and keep a common part) which will insert the selected text into a third pane which can be also used to edit the result. Mergepy uses python's standard 'difflib' to segment the files and uses textual, uses a rich renderable to highlight the syntax for the 2 file panes and uses treesitter to highlight the syntax in the editor pane.

🎬 Demo

Mergepy demo

📥 Installing

It's adviced to install this project using something like pipx to install a project from pip systemwide:

pipx install mergepy

If you're using bash or zsh (linux, macOs), it's advisable to install argcomplete from your available packagemanager so you can autocomplete mergepy's flags and options in the terminal.

Debian (Linux):

sudo apt install python3-argcomplete

Arch (Linux):

sudo pacman -S python-argcomplete

macOs:

brew install argcomplete

After installing argcomplete, run activate-global-python-argcomplete to activate autocompletions for all installed python packages If that doesn't work or you don't want to do that, you can also always just add autocompletion for one specific package. For mergepy autocompletion only, put this in you ~/.bashrc or ~/.zshrc:

eval "$(register-python-argcomplete mergepy)"

Once everything is installed, just run:

mergepy filename1 filename2

to pick out your preffered changes between 2 similar files

✨ Flags and features

Mergepy flags

  • Mergepy expects the paths of 2 filenames to start up
  • When supplying mergepy with the --output, -o 'filename' flag before starting up, you can preset to what file the output will be written to. If the flag was not supplied, mergepy will attempt to bring up a file-explorer when you want to save.
  • By default, mergepy will look at the extension of the filename and base the syntax of the file and merge pane on said extension. When --language, -l 'language' is given before starting up, mergepy will force said language for the syntaxing (for the editor part - option for the filepanes to come). Available options are 'typescript, javascript, python, swift bash, zsh, yaml, rust, ruby, html, java, json, php, css, c, cpp and go'
  • By default, mergepy will attempt to automatically merge common blocks. This feature can be turned off using --no-automerge-common, -m
  • By default, mergepy will attempt to autoscroll to the associated block in the second filepane when scrolling through one of the filepanes. This behaviour can be turned off with the --no-autosync, -s flag, though when given you can still manually sync by pressing space when hovering over a block.
  • To set the syntaxtheme for the filepanes, use --file-theme, -f 'theme'. These panes use Rich renderable from textual for syntaxing, which uses the selection of themes from pygments as options.
  • To set the syntaxtheme for the mergepane, use --editor-theme, -e 'theme'. This pane uses python's treesitter for syntaxing. The options for this flag are: 'css(default)', 'dracula', 'vscode_dark', 'github_light', 'monokai'

⌨ Actions

Mergepy includes a footer, provided by Textual, that shows the available commands. These are:

  • Enter: This will Replace a different textblock and keep a common textblock
  • R - Replace: Only available for different textblocks; keeps the highlighted block for one file, removes the associated block for the other file
  • K - Keep: Keeps the currently highlighted block without removing the block in the other file note: keeping a common blocks will remove the same block in the second file to avoid duplicates
  • Up/down inside of filepanes: Select the next block
  • Ctrl-up/down/left/right: Move to next pane
  • Shift-up/down/left/right inside file panes: Scroll through pane
  • Shift-up/down/left/right inside merge pane: Select text
  • Alt-up/down inside file panes: Scroll to next conflict
  • Alt-up/down/left/right inside merge pane: Scroll through text
  • Space: Sync conflicts (only necessary when using the --no-autosync, -s flag)
  • Ctrl-z: undo
  • Ctrl-y: redo
  • Ctrl-s: save
  • Ctrl-q: quit; will bring up a warning if you have not saved before.

🛠️ Technologies

The project is built with:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mergepy-1.2.5.tar.gz (29.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mergepy-1.2.5-py3-none-any.whl (26.7 kB view details)

Uploaded Python 3

File details

Details for the file mergepy-1.2.5.tar.gz.

File metadata

  • Download URL: mergepy-1.2.5.tar.gz
  • Upload date:
  • Size: 29.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for mergepy-1.2.5.tar.gz
Algorithm Hash digest
SHA256 f71324176fe7cbc36c3c61b4d7bfc629911b5adc65aeab6f66971871441a6d26
MD5 ae3ab5e429cf53a664b783cf03cbba0a
BLAKE2b-256 541fe9d9abb3ef51184986ccb720206190ace4bdacd95efa869bdaf1a69219d8

See more details on using hashes here.

File details

Details for the file mergepy-1.2.5-py3-none-any.whl.

File metadata

  • Download URL: mergepy-1.2.5-py3-none-any.whl
  • Upload date:
  • Size: 26.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for mergepy-1.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e22ca4fdc8b411851d4ce33fbc718fecf8d746b85fdfb96743e5a615f47c69e3
MD5 a83e311af7710ca7ed6950a5edae4dfb
BLAKE2b-256 2bd631e07afd5e5d488f07a3048edb8ed80b3c055446838a58d197e4749e97af

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page