├── .gitignore ├── LICENSE ├── README.md ├── addalias ├── data ├── addalias.desktop └── addalias.png ├── setup.py ├── src ├── __init__.py └── addalias.py └── ui ├── tab_addalias.ui └── tab_alias.ui /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | 5 | # C extensions 6 | *.so 7 | 8 | # Distribution / packaging 9 | .Python 10 | env/ 11 | bin/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | eggs/ 16 | lib/ 17 | lib64/ 18 | parts/ 19 | sdist/ 20 | var/ 21 | *.egg-info/ 22 | .installed.cfg 23 | *.egg 24 | 25 | # Installer logs 26 | pip-log.txt 27 | pip-delete-this-directory.txt 28 | 29 | # Unit test / coverage reports 30 | htmlcov/ 31 | .tox/ 32 | .coverage 33 | .cache 34 | nosetests.xml 35 | coverage.xml 36 | 37 | # Translations 38 | *.mo 39 | 40 | # Mr Developer 41 | .mr.developer.cfg 42 | .project 43 | .pydevproject 44 | 45 | # Rope 46 | .ropeproject 47 | 48 | # Django stuff: 49 | *.log 50 | *.pot 51 | 52 | # Sphinx documentation 53 | docs/_build/ 54 | 55 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 İsa Mert Gürbüz 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Info 2 | Addalias is a simple tool for adding/editing your alias commands. You can use it with a simple GUI or you can use it with commandline. 3 | 4 | Alias is a command for creating shortcuts for other commands. For example, if you are using Ubuntu, everytime you want to install a program you have to type "sudo apt-get install". You can install programs with just typing "install". What you have to do is add an alias to this command. Aliases are stored in ~/.bashrc. This tool adds/edits aliases easily without touching the file. 5 | 6 | ## INSTALLING: 7 | Just download the package, extract it. Enter in the "src" folder. Open terminal here and type "python addalias.py --install". Now you can use by just typing "addalias". 8 | 9 | ## Screenshots 10 | ### Using with commandline 11 |  12 | 13 | ### Using with GUI 14 |  ---  15 | -------------------------------------------------------------------------------- /addalias: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys,os 4 | from os.path import dirname, join, pardir 5 | 6 | try: 7 | from addalias import addalias 8 | except ImportError: 9 | basedir = os.path.dirname(os.path.realpath(__file__)) 10 | workdir = join(basedir,'src') 11 | sys.path.insert(0, workdir) 12 | os.chdir(workdir) 13 | import addalias 14 | 15 | addalias.main(sys.argv) 16 | -------------------------------------------------------------------------------- /data/addalias.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=Addalias 3 | Terminal=false 4 | Exec=addalias -gui 5 | Icon=addalias 6 | Type=Application 7 | Categories==System;Utility; 8 | -------------------------------------------------------------------------------- /data/addalias.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isamert/addalias/5c5add4046465634debe627f8c534ffb9bc4cf20/data/addalias.png -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | from distutils.core import setup 5 | 6 | APPVERSION = '1.1' 7 | 8 | setup( 9 | name='addalias', 10 | version=APPVERSION, 11 | author='İsa Mert Gürbüz', 12 | author_email='isamertgurbuz@gmail.com', 13 | description='A graphical and a commandline tool for adding/editing alias command.', 14 | url='https://github.com/isamert/addalias', 15 | license='MIT', 16 | scripts=['addalias'], 17 | data_files = [ 18 | ('share/applications', ['data/addalias.desktop']), 19 | ('share/doc/addalias-%s' % APPVERSION, ['LICENSE', 'README.md']), 20 | ('share/pixmaps', ['data/addalias.png']), 21 | ], 22 | package_dir={'addalias': 'src'}, 23 | packages=['addalias'], 24 | ) 25 | -------------------------------------------------------------------------------- /src/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isamert/addalias/5c5add4046465634debe627f8c534ffb9bc4cf20/src/__init__.py -------------------------------------------------------------------------------- /src/addalias.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | import os 5 | import sys 6 | from PyQt4 import QtGui, QtCore 7 | 8 | ERR_SAME = "You have same alias, try different." 9 | SUCCESS = "Success!" 10 | 11 | class Operations: 12 | def __init__(self): 13 | self.bash_file = os.path.expanduser("~/.bashrc") 14 | self.path = os.path.realpath(__file__) 15 | self.install_dir = os.path.expanduser("~/.local/share/addalias") 16 | self.install_path = os.path.join(self.install_dir, __file__) 17 | 18 | def check(self, lines, alias): 19 | for line in lines: 20 | if line.startswith("alias " + alias + "="): 21 | return False 22 | return True 23 | 24 | def add_alias(self, alias, command): 25 | with open(self.bash_file, 'a+') as f: 26 | if self.check(f.readlines(), alias): 27 | txt = "" 28 | if str(command).startswith("'") and str(command).endswith("'"): 29 | txt = "alias %s=%s\n" % (alias, command) 30 | else: 31 | txt = "alias %s='%s'\n" % (alias, command) 32 | f.write(txt) 33 | print SUCCESS 34 | return True 35 | else: 36 | return False 37 | 38 | def delete(self, alias): 39 | #TODO: delete by id 40 | f = open(self.bash_file, "r") 41 | lines = f.readlines() 42 | f.close() 43 | 44 | f = open(self.bash_file,"w") 45 | 46 | for line in lines: 47 | if not line.startswith("alias " + alias + "="): 48 | f.write(line) 49 | 50 | f.close() 51 | print SUCCESS 52 | 53 | def aliaslist(self): 54 | aliases = [] 55 | if not os.path.isfile(self.bash_file): 56 | open(self.bash_file, 'a').close() 57 | with open(self.bash_file, 'r') as f: 58 | for line in f.readlines(): 59 | if line.startswith("alias"): 60 | cmdline = line.replace("alias", "", 1).strip() 61 | aliases.append(cmdline) 62 | return aliases 63 | 64 | 65 | def print_aliases(self): 66 | i = 0 67 | for line in self.aliaslist(): 68 | print "[" + str(i) + "] " + line 69 | i += 1 70 | 71 | def install(self): 72 | import shutil 73 | 74 | if not os.path.exists(self.install_dir): os.mkdir(self.install_dir) 75 | if os.path.isfile(self.install_path): os.remove(self.install_path) 76 | 77 | shutil.copyfile(self.path, self.install_path) 78 | self.add_alias("addalias", "python " + self.install_path) 79 | print "\tnow you can use 'addalias -parameters'" 80 | print "\tbefore using you have to close this terminal window and reopen" 81 | print "\tfor example" 82 | print '\t\taddalias -add "my-alias" "my-command"' 83 | 84 | def uninstall(self): 85 | self.delete("addalias") 86 | os.remove(self.install_path) 87 | os.rmdir(self.install_dir) 88 | print SUCCESS 89 | 90 | 91 | 92 | operations = Operations() 93 | 94 | 95 | class AddEditAlias(QtGui.QWidget): 96 | def __init__(self, parent = None): 97 | super(AddEditAlias, self).__init__(parent) 98 | self.old_alias = None 99 | 100 | self.setWindowTitle("Edit Alias") 101 | self.gridLayout = QtGui.QGridLayout(self) 102 | self.buttons_addalias = QtGui.QDialogButtonBox(self) 103 | self.buttons_addalias.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok) 104 | self.gridLayout.addWidget(self.buttons_addalias, 3, 0, 1, 1) 105 | self.layout_addalias = QtGui.QFormLayout() 106 | self.layout_addalias.setFieldGrowthPolicy(QtGui.QFormLayout.AllNonFixedFieldsGrow) 107 | self.lbl_command = QtGui.QLabel(self) 108 | self.layout_addalias.setWidget(1, QtGui.QFormLayout.LabelRole, self.lbl_command) 109 | self.lbl_alias = QtGui.QLabel(self) 110 | self.layout_addalias.setWidget(0, QtGui.QFormLayout.LabelRole, self.lbl_alias) 111 | self.line_alias = QtGui.QLineEdit(self) 112 | self.layout_addalias.setWidget(0, QtGui.QFormLayout.FieldRole, self.line_alias) 113 | self.line_command = QtGui.QLineEdit(self) 114 | self.layout_addalias.setWidget(1, QtGui.QFormLayout.FieldRole, self.line_command) 115 | self.gridLayout.addLayout(self.layout_addalias, 1, 0, 1, 1) 116 | self.line_1 = QtGui.QFrame(self) 117 | self.line_1.setFrameShape(QtGui.QFrame.HLine) 118 | self.line_1.setFrameShadow(QtGui.QFrame.Sunken) 119 | self.gridLayout.addWidget(self.line_1, 2, 0, 1, 1) 120 | 121 | self.lbl_alias.setText("Alias:") 122 | self.lbl_command.setText("Command:") 123 | 124 | 125 | class GUI(QtGui.QMainWindow): 126 | def __init__(self, parent = None): 127 | super(GUI, self).__init__(parent) 128 | self.setWindowTitle("Add alias") 129 | self.load_tabwidget() 130 | self.setCentralWidget(self.tabwidget) 131 | self.load_windowedit() 132 | self.load_list() 133 | self.show() 134 | 135 | def load_windowedit(self): 136 | self.window_edit = AddEditAlias() 137 | self.connect(self.window_edit.buttons_addalias, QtCore.SIGNAL("accepted()"), self.alias_edit_ok) 138 | self.connect(self.window_edit.buttons_addalias, QtCore.SIGNAL("rejected()"), self.window_edit.hide) 139 | 140 | def load_tabwidget(self): 141 | self.tabwidget = QtGui.QTabWidget() 142 | self.load_tabaddalias() 143 | self.load_tabalias() 144 | 145 | self.tabwidget.addTab(self.tab_addalias, "Add New Alias") 146 | self.tabwidget.addTab(self.tab_alias, "Edit Aliases") 147 | 148 | def load_tabaddalias(self): 149 | self.tab_addalias = AddEditAlias() 150 | 151 | self.connect(self.tab_addalias.buttons_addalias, QtCore.SIGNAL("accepted()"), self.alias_add) 152 | self.connect(self.tab_addalias.buttons_addalias, QtCore.SIGNAL("rejected()"), QtGui.qApp.quit) 153 | 154 | def load_tabalias(self): 155 | self.tab_alias = QtGui.QWidget() 156 | 157 | self.gridLayout = QtGui.QGridLayout(self.tab_alias) 158 | self.layout_vertical2 = QtGui.QVBoxLayout() 159 | self.lbl_aliases = QtGui.QLabel(self.tab_alias) 160 | self.layout_vertical2.addWidget(self.lbl_aliases) 161 | self.list_alias = QtGui.QListWidget(self.tab_alias) 162 | self.layout_vertical2.addWidget(self.list_alias) 163 | self.gridLayout.addLayout(self.layout_vertical2, 0, 0, 1, 1) 164 | self.layout_vertical = QtGui.QVBoxLayout() 165 | self.btn_edit = QtGui.QPushButton(self.tab_alias) 166 | self.layout_vertical.addWidget(self.btn_edit) 167 | self.btn_delete = QtGui.QPushButton(self.tab_alias) 168 | self.layout_vertical.addWidget(self.btn_delete) 169 | spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) 170 | self.layout_vertical.addItem(spacerItem) 171 | self.gridLayout.addLayout(self.layout_vertical, 0, 2, 1, 1) 172 | self.line_2 = QtGui.QFrame(self.tab_alias) 173 | self.line_2.setFrameShape(QtGui.QFrame.VLine) 174 | self.line_2.setFrameShadow(QtGui.QFrame.Sunken) 175 | self.gridLayout.addWidget(self.line_2, 0, 1, 1, 1) 176 | 177 | self.lbl_aliases.setText("Aliases:") 178 | self.btn_edit.setText("Edit") 179 | self.btn_delete.setText("Delete") 180 | 181 | self.btn_delete.clicked.connect(self.alias_delete) 182 | self.btn_edit.clicked.connect(self.alias_edit) 183 | 184 | def load_list(self): 185 | self.list_alias.clear() 186 | for alias in operations.aliaslist(): 187 | self.list_alias.addItem(alias) 188 | 189 | def alias_delete(self): 190 | try: 191 | alias = self.list_alias.selectedItems()[0].text().split("=", 1)[0] 192 | operations.delete(alias) 193 | self.load_list() 194 | except IndexError: 195 | pass 196 | 197 | def alias_edit(self): 198 | try: 199 | _alias = self.list_alias.selectedItems()[0].text().split("=", 1) 200 | self.window_edit.line_alias.setText(_alias[0]) 201 | self.window_edit.line_command.setText(_alias[1]) 202 | self.window_edit.old_alias = _alias[0] 203 | self.window_edit.show() 204 | self.load_list() 205 | except IndexError: 206 | pass 207 | 208 | def alias_edit_ok(self): 209 | if self.window_edit.old_alias != None: 210 | operations.delete(self.window_edit.old_alias) 211 | operations.add_alias(self.window_edit.line_alias.text(), self.window_edit.line_command.text()) 212 | self.window_edit.old_alias = None 213 | self.load_list() 214 | self.window_edit.hide() 215 | 216 | def alias_add(self): 217 | if operations.add_alias(self.tab_addalias.line_alias.text(), self.tab_addalias.line_command.text()): 218 | self.load_list() 219 | QtGui.QMessageBox.information(self, SUCCESS, "You have successfully added new alias!") 220 | else: 221 | QtGui.QMessageBox.warning(self, "Error", ERR_SAME) 222 | 223 | def main(argv = None): 224 | if argv is None: 225 | argv = sys.argv 226 | 227 | number = len(argv) 228 | 229 | if number == 1: 230 | print 'try typing --help' 231 | 232 | elif number == 2: 233 | if argv[1] == '--help': 234 | print "" 235 | print '\tusage:' 236 | print '\t\tadd new alias: python addalias.py -add "