diff --git a/scripts/asciidoc2html.py b/scripts/asciidoc2html.py
index dab01e12c..878311eb6 100755
--- a/scripts/asciidoc2html.py
+++ b/scripts/asciidoc2html.py
@@ -61,6 +61,7 @@ def call_asciidoc(src, dst):
def main(colors=False):
"""Generate html files for the online documentation."""
+ utils.change_cwd()
utils.use_color = colors
asciidoc_files = [
('doc/FAQ.asciidoc', 'qutebrowser/html/doc/FAQ.html'),
diff --git a/scripts/cleanup.py b/scripts/cleanup.py
index 6920d1a32..938c677e7 100755
--- a/scripts/cleanup.py
+++ b/scripts/cleanup.py
@@ -27,6 +27,10 @@ import glob
import shutil
import fnmatch
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir))
+
+from scripts import utils
+
recursive_lint = ('__pycache__', '*.pyc')
lint = ('build', 'dist', 'pkg/pkg', 'pkg/qutebrowser-*.pkg.tar.xz', 'pkg/src',
@@ -49,6 +53,7 @@ def remove(path):
def main():
"""Clean up lint in the current dir."""
+ utils.change_cwd()
for elem in lint:
for f in glob.glob(elem):
remove(f)
diff --git a/scripts/quit_segfault_test.sh b/scripts/quit_segfault_test.sh
index e367b53b7..655eb262a 100755
--- a/scripts/quit_segfault_test.sh
+++ b/scripts/quit_segfault_test.sh
@@ -1,4 +1,9 @@
#!/bin/bash
+
+if [[ $PWD == */scripts ]]; then
+ cd ..
+fi
+
echo > crash.log
while :; do
exit=0
diff --git a/scripts/run_checks.py b/scripts/run_checks.py
index bebd677fc..d38034640 100755
--- a/scripts/run_checks.py
+++ b/scripts/run_checks.py
@@ -279,6 +279,7 @@ def _checker_enabled(args, group, name):
def main():
"""Main entry point."""
global config
+ utils.change_cwd()
read_files = config.read('.run_checks')
if not read_files:
raise IOError("Could not read config!")
diff --git a/scripts/run_profile.py b/scripts/run_profile.py
index 8851a423d..3b6f111a7 100755
--- a/scripts/run_profile.py
+++ b/scripts/run_profile.py
@@ -31,6 +31,7 @@ import shutil
sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir))
import qutebrowser.qutebrowser # pylint: disable=unused-import
+from scripts import utils
tempdir = tempfile.mkdtemp()
diff --git a/scripts/src2asciidoc.py b/scripts/src2asciidoc.py
index fc47daef2..ceef9babb 100755
--- a/scripts/src2asciidoc.py
+++ b/scripts/src2asciidoc.py
@@ -35,7 +35,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir))
# We import qutebrowser.app so all @cmdutils-register decorators are run.
import qutebrowser.app
-from scripts import asciidoc2html
+from scripts import asciidoc2html, utils
from qutebrowser import qutebrowser
from qutebrowser.commands import cmdutils
from qutebrowser.config import configdata
@@ -395,6 +395,7 @@ def regenerate_manpage(filename):
def main():
"""Regenerate all documentation."""
+ utils.change_cwd()
print("Generating manpage...")
regenerate_manpage('doc/qutebrowser.1.asciidoc')
print("Generating settings help...")
diff --git a/scripts/update_3rdparty.py b/scripts/update_3rdparty.py
index fe1615876..a14425769 100755
--- a/scripts/update_3rdparty.py
+++ b/scripts/update_3rdparty.py
@@ -20,8 +20,16 @@
"""Update 3rd-party files (currently only ez_setup.py)."""
+import sys
+import os
+import os.path
import urllib.request
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir))
+
+from scripts import utils
+
+utils.change_cwd()
urllib.request.urlretrieve(
'https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py',
'scripts/ez_setup.py')
diff --git a/scripts/utils.py b/scripts/utils.py
index daa3a7dcc..5b0c7dc72 100644
--- a/scripts/utils.py
+++ b/scripts/utils.py
@@ -20,6 +20,7 @@
"""Utility functions for scripts."""
import os
+import os.path
use_color = True
@@ -82,3 +83,10 @@ def print_bold(text):
print(''.join([bold, text, reset]))
else:
print(text)
+
+
+def change_cwd():
+ """Change the scripts cwd if it was started inside the script folder."""
+ cwd = os.getcwd()
+ if os.path.split(cwd)[1] == 'scripts':
+ os.chdir(os.path.join(cwd, os.pardir))